RE: [xsl] xsl:element in XSLT 1.0

Subject: RE: [xsl] xsl:element in XSLT 1.0
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Wed, 22 Jun 2005 23:06:39 +0100
> Here is an example of my problem:
> <?xml version="1.0"?>
> <xsl:stylesheet xmlns:xsl="";  
> version="1.0">
>    <xsl:template match="*">
>      <out>
>        <xsl:element name="foo" xmlns:a="bar">
>          <child/>
>        </xsl:element>
>      </out>
>    </xsl:template>
> </xsl:stylesheet>
> Xalan produces this:
> <out><foo xmlns:a="bar"><child/></foo></out>
> While Saxon produces this:
> <out><foo><child xmlns:a="bar"/></foo></out>
> Honestly, I can see both of these outputs being reasonable. In  
> Xalan's defense, if 'foo' were simply a literal result 
> element in the  
> stylesheet, the declaration would be part of 'foo'. In Saxon's  
> defense, the 'bar' namespace is declared on an element only used in  
> the stylesheet, and therefore it does not apply to element results  
> until 'child' is inserted into the result tree.

Don't try to apply reasoning based on what seems "reasonable": you've got to
read what the spec says.

The spec says that in the result tree, <child> has a namespace node (a=bar),
and <foo> does not. However, the XSLT 1.0 spec gives the serializer free
rein to add namespace declarations anywhere it likes. So both outputs are

In 2.0, the serializer has much less freedom of action, and the first output
would be wrong.

Michael Kay

Current Thread