JDK-8168664 : [JAXP] XALAN: xsl:element generates namespace prefixes if namespace is given as URI only
  • Type: Bug
  • Component: xml
  • Sub-Component: javax.xml.transform
  • Affected Version: 9
  • Priority: P4
  • Status: In Progress
  • Resolution: Unresolved
  • Submitted: 2016-10-25
  • Updated: 2024-08-28
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
tbdUnresolved
Related Reports
Relates :  
Description
The Xalan XSLTC transformator currently generates namespace prefixes when a namespace comes in as URI only. This behavior is at least not optimal, maybe a clear bug.

Consider the following input:
<?xml version="1.0" encoding="utf-8"?>
<clns:nodel1 xmlns:clns="http://sap.com/cl/1">
        <clns:nodel2a xmlns:clns="http://sap.com/cl/1">VALUE1</clns:nodel2a>
        <clns:nodel2b xmlns:clns="http://sap.com/cl/1">VALUE2</clns:nodel2b>
</clns:nodel1>

This is the transformation xsl:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
        <!-- Author: Christoph Langer -->
        <!-- This XSLT should remove namespace prefixes from the input -->
        <xsl:template match="/">
                <result xmlns="http://sap.com/cl">
                        <xsl:copy>
                                <xsl:apply-templates select="*"/>
                        </xsl:copy>
                </result>
        </xsl:template>
        <xsl:template match="*">
                <xsl:element name="{local-name()}" namespace="{namespace-uri()}">
                        <xsl:apply-templates select="@*|node()"/>
                </xsl:element>
        </xsl:template>
        <xsl:template match="@*">
                <xsl:attribute name="{local-name()}"><xsl:value-of select="."/></xsl:attribute>
        </xsl:template>
</xsl:stylesheet>

an output like this is expected:
<?xml version="1.0" encoding="UTF-8"?><result xmlns="http://sap.com/cl"><nodel1 xmlns="http://sap.com/cl/1">
        <nodel2a>VALUE1</nodel2a>
        <nodel2b>VALUE2</nodel2b>
</nodel1></result>

but currently we get:
<?xml version="1.0" encoding="UTF-8"?><result xmlns="http://sap.com/cl"><ns0:nodel1 xmlns:ns0="http://sap.com/cl/1">
        <ns1:nodel2a xmlns:ns1="http://sap.com/cl/1">VALUE1</ns1:nodel2a>
        <ns2:nodel2b xmlns:ns2="http://sap.com/cl/1">VALUE2</ns2:nodel2b>
</ns0:nodel1></result>

In the current output the namespaces ns0, ns1 and ns2 are generated and added to the qname of the nodes nodel1, nodel2a and nodel2b. 

However, I would rather expect the output to generate an xmlns="http://sap.com/cl/1" entry for nodel1, serving as the default namespace for nodel1 and its siblings.