-
Bug
-
Resolution: Unresolved
-
P4
-
9
-
None
-
Cause Known
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.
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.
- relates to
-
JDK-8167179 Make XSL generated namespace prefixes local to transformation process
- Resolved