JAXP: XSLTC transformer swallows empty namespace declaration which is necessary to undeclare default namespace

huizhe wang huizhe.wang at oracle.com
Tue Jul 26 06:40:00 UTC 2016

On 7/22/2016 3:38 AM, Langer, Christoph wrote:
> Hi,
> I have a customer reporting the following phenomena which I believe is an issue.
> Consider the following xsl:
> ---------------------XSL---------------------
> <?xml version="1.0" encoding="UTF-8"?>
> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
>                  <xsl:template match="/">
>                                 <root xmlns="ns1">
>                                                 <xsl:call-template name="transform"/>
>                                 </root>
>                  </xsl:template>
>                  <xsl:template name="transform">
>                  <test xmlns=""/>
>                  </xsl:template>
> </xsl:stylesheet>
> ---------------------End of XSL---------------------
> This is the XML snippet where the XSL gets applied (just a dummy):
> <?xml version="1.0" encoding="UTF-8"?><aaa></aaa>
> The result with the current XSLTC is:
> <?xml version="1.0" encoding="UTF-8"?><root xmlns="ns1"><test/></root>
> But this would not undeclare the default namespace "ns1" from the element named "root" for the element named "test" which was the intention of the xsl. So I believe it should be:
> <?xml version="1.0" encoding="UTF-8"?><root xmlns="ns1"><test xmlns=""/></root>
> Looking at the coding I came up with the following: http://cr.openjdk.java.net/~clanger/webrevs/xsltc-namespaceissue/ With that, XSLTC would also emit the namespace attribute for an empty namespace. It works for my example but I'm not sure if it is the right thing to do or if it breaks things at other places and violates specs elsewhere.

I'm not sure why empty namespace was explicitly excluded. But for the 
2nd part, the developer was clear with a note on the intention. You may 
want to try removing the condition statement that excluded the empty 
namespace, but keep the 2nd part as is, and then run the tests to see if 
there's any issue or a reason why it was excluded.
> Comparing with the Apache Xalan, I can see that the Apache XSLTC matches the JDK XSLTC behavior to suppress the namespace declaration but the interpretative transformer (org.apache.xalan.processor.TransformerFactoryImpl) would emit the namespace attribute.

Ok, the interpretative may be correct.

On another thought, if the following workaround works for you, we may as 
well leave the current implementation as is:
try replacing <test xmlns=""/> in the above, with <xsl:element 
name=\"test\" namespace=\"\" />"


> Please give me some comments before I open a Bug...
> Thanks a lot in advance
> Christoph

More information about the core-libs-dev mailing list