RE: [xsl] namespace declarations in generated stylesheet

Subject: RE: [xsl] namespace declarations in generated stylesheet
From: "Michael Kay" <mhk@xxxxxxxxx>
Date: Fri, 11 Apr 2003 19:54:42 +0100
I can't see any reason why Xalan should be copying namespaces from the
stylesheet to the output here. The only instruction that copies
namespaces from the stylesheet is a literal result element, and your
stylesheet does not contain any literal result elements.

> I thought I ought to be able to just whip up a 
> set of namespace declarations with something like:
> 
> <xsl:element name="xsl:stylesheet">
>   <xsl:attribute name="xmlns:my">
>     <xsl:text>http://www.my.net/my markup</xsl:text>
>   </xsl:attribute>
> </xsl:element>
> 
> But that don't work for either tool and I think I am just 
> beginning to see why. Can anyone enlighten me?

xsl:attribute is used to create attribute nodes, it cannot be used to
create namespace nodes. These might look like attributes in the surface
syntax of XML, but they are quite different in the data model.

XSLT 2.0 has an <xsl:namespace> instruction to achieve this effect. It's
more difficult in XSLT 1.0; if you really want to create a namespace
declaration that isn't referenced in any element or attribute name, the
only way to do it is:

<xsl:variable name="dummy">
  <xsl:element name="my:x" namespace="http://www.my.net/my markup"/>
</xsl:variable>

<xsl:copy-of select="xx:node-set($dummy)//namespace::*"/>

Michael Kay
Software AG
home: Michael.H.Kay@xxxxxxxxxxxx
work: Michael.Kay@xxxxxxxxxxxxxx 

> -----Original Message-----
> From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx 
> [mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx] On Behalf Of 
> Mike Haarman
> Sent: 11 April 2003 18:52
> To: xsl-list
> Subject: [xsl] namespace declarations in generated stylesheet
> 
> 
> Hey all,
> 
> I have noticed a remarkable discrepancy between the behavior 
> of Saxon and Xalan over the following stylesheet and instance:
> 
> --------------------------------------------------------------
> ------------------
> --------
> <?xml version="1.0" encoding="utf-8"?>
> <my:document xmlns:my="http://www.my.net/MyMarkup";>
> <element status="current" name="report"/>
> </my:document>
> 
> 
> --------------------------------------------------------------
> ------------------
> --------
> <?xml version="1.0" encoding="utf-8"?>
> <xsl:stylesheet version="1.0"
>   xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
>   xmlns:fo="http://www.w3.org/1999/XSL/Format";
>   xmlns:fox="http://xml.apache.org/fop/extensions";
>   xmlns:my="http://www.my.net/MyMarkup";
> >
>   <xsl:output method="xml"
>     encoding="utf-8"/>
>   <xsl:template match="/">
>     <xsl:element name="xsl:stylesheet">
>       <xsl:element name="xsl:param">
>         <xsl:attribute name="name">
>           <xsl:text>report.style</xsl:text>
>         </xsl:attribute>
>         <xsl:attribute name="select">
>           <xsl:text>/root/param[@name = 'style']/@value</xsl:text>
>         </xsl:attribute>
>       </xsl:element>
>     </xsl:element>
>     <xsl:apply-templates/>
>   </xsl:template>
> </xsl:stylesheet>
> 
> 
> 
> In generating the xsl:stylesheet declaration in the result, 
> Saxon won't allow me to declare anything other than xslns:xsl 
> and this it does for me.  Xalan also won't let me change it 
> but returns all the namespaces declared on the stylesheet 
> generating the output.
> 
> Saxon output:
> --------------------------------------------------------------
> ------------------
> --------
> <?xml version="1.0" encoding="utf-8"?><xsl:stylesheet 
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
> <xsl:param name="report.style" select="/root/param[@name = 
> 'style']/@value"/></xsl:stylesheet>
> 
> Xalan output:
> --------------------------------------------------------------
> ------------------
> --------
> <?xml version="1.0" encoding="utf-8"?>
> <xsl:stylesheet xmlns:my="http://www.my.net/MyMarkup";
> xmlns:fox="http://xml.apache.org/fop/extensions";
> xmlns:fo="http://www.w3.org/1999/XSL/Format";
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
> <xsl:param name="report.style" select="/root/param[@name = 
> 'style']/@value"/></xsl:stylesheet>
> 
> 
> The question is, who's right?  What behavior should I be 
> expecting?  I thought I ought to be able to just whip up a 
> set of namespace declarations with something
> like:
> 
> <xsl:element name="xsl:stylesheet">
>   <xsl:attribute name="xmlns:my">
>     <xsl:text>http://www.my.net/my markup</xsl:text>
>   </xsl:attribute>
> </xsl:element>
> 
> But that don't work for either tool and I think I am just 
> beginning to see why. Can anyone enlighten me?
> 
> 
> Much obliged,
> 
> Mike Haarman
> 
> 
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
> 


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread