xmlns="" missing in 8.9 (but ok in 6.5)
Added by Anonymous about 17 years ago
Legacy ID: #4569911 Legacy Poster: Andrew Fang (afang4)
A trimmed down test case is attached. Note that in the output from saxon 6.5, xmlns="" is present in xsl:element <x:element xmlns="" name="{name(.)}"> However, in 8.9, it is missing: <x:element name="{name(.)}"> What should be the correct behavior? Thanks for your help. Andrew ---- test case ----------------------------------------------- Input source: <?xml version="1.0" encoding="UTF-8"?> <doc/> XSL: <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:x="http://www.w3.org/1999/XSL/TransformAlias" xmlns="http://www.w3.org/1999/xhtml" version="1.0" > <xsl:output indent="yes" method="xml" omit-xml-declaration="no" encoding="UTF-8"/> <xsl:template match="/"> <x:stylesheet version="1.0"> <x:template match="h:" mode="remove-xhtml-namespace" xmlns:h="http://www.w3.org/1999/xhtml"> <x:element name="{{name(.)}}" xmlns=""> <x:copy-of select="@"/> <x:apply-templates mode="remove-xhtml-namespace"/> </x:element> </x:template> </x:stylesheet> </xsl:template> </xsl:stylesheet> 6.5 Output: <?xml version="1.0" encoding="UTF-8" standalone="no"?> <x:stylesheet xmlns:x="http://www.w3.org/1999/XSL/TransformAlias" xmlns="http://www.w3.org/1999/xhtml" version="1.0"> <x:template xmlns:h="http://www.w3.org/1999/xhtml" match="h:" mode="remove-xhtml-namespace"> <x:element xmlns="" name="{name(.)}"> <x:copy-of select="@"/> <x:apply-templates mode="remove-xhtml-namespace"/> </x:element> </x:template> </x:stylesheet> 8.9 Output: <?xml version="1.0" encoding="UTF-8"?> <x:stylesheet xmlns="http://www.w3.org/1999/xhtml" xmlns:x="http://www.w3.org/1999/XSL/TransformAlias" version="1.0"> <x:template xmlns:h="http://www.w3.org/1999/xhtml" match="h:" mode="remove-xhtml-namespace"> <x:element name="{name(.)}"> <x:copy-of select="@"/> <x:apply-templates mode="remove-xhtml-namespace"/> </x:element> </x:template> </x:stylesheet>
Replies (4)
Please register to reply
RE: xmlns="" missing in 8.9 (but ok in 6.5) - Added by Anonymous about 17 years ago
Legacy ID: #4570325 Legacy Poster: Michael Kay (mhkay)
I think the 8.9 output is correct according to the XSLT 2.0 specification. xmlns="" is a namespace undeclaration, so its effect in the stylesheet is that the literal result element x:element does not have a namespace node with the empty prefix. When the x:element element is created in the result tree, however, it is given (a) copies of all the namespace nodes from the LRE in the stylesheet, and (b) copies of namespace nodes inherited from its new parent in the result tree (see rule 12 of 5.7.1 Constructing Complex Content). You can prevent this by specifying xsl:inherit-namespaces="no" on the parent of the x:element, that is on the x:template LRE. In XSLT 1.0, processors had much more discretion about generating namespace declarations, so it would be hard to argue that the Saxon 6.5 behaviour is not conformant with the 1.0 specification. Does this change in behaviour have any material consequences?
RE: xmlns="" missing in 8.9 (but ok in 6.5) - Added by Anonymous about 17 years ago
Legacy ID: #4570374 Legacy Poster: Andrew Fang (afang4)
There is a big material consequence--things no longer work for us. We are using XSLT to generate XSLT stylesheets. What we are trying to generate is the following template <xsl:template xmlns:h="http://www.w3.org/1999/xhtml" match="h:" mode="remove-xhtml-namespace"> <xsl:element xmlns="" name="{name(.)}"> <xsl:copy-of select="@"/> <xsl:apply-templates mode="remove-xhtml-namespace"/> </xsl:element> </xsl:template> and the code we show does generate that template using 6.5. Using 8.9, we instead get: <xsl:template xmlns:h="http://www.w3.org/1999/xhtml" match="h:" mode="remove-xhtml-namespace"> <xsl:element name="{name(.)}"> <xsl:copy-of select="@"/> <xsl:apply-templates mode="remove-xhtml-namespace"/> </xsl:element> </xsl:template> When the 6.5 generated stylesheet is used, it generates HTML as desired. When the 8.9 generated stylesheet is used, it generates XHTML--as expected due to the missing xmlns="" from the generated template--and this is a serious problem for us. Is there a way to generate output as 6.5 using 8.9?
RE: xmlns="" missing in 8.9 (but ok in 6.5) - Added by Anonymous about 17 years ago
Legacy ID: #4571348 Legacy Poster: Michael Kay (mhkay)
Your best bet is to generate <xsl:element namespace="" name="{local-name(.)}"> That way you avoid depending on (a) the exact details of how namespace fixup is done (which is to some degree implementation-defined) and (b) the user's choice of namespace prefixes in the input document. Michael Kay
RE: xmlns="" missing in 8.9 (but ok in 6.5) - Added by Anonymous about 17 years ago
Legacy ID: #4572130 Legacy Poster: Andrew Fang (afang4)
That is a great solution. Thanks a lot! Andrew
Please register to reply