xsl-list
[Top] [All Lists]

xsl:element in XSLT 1.0

2005-06-22 13:42:17
This is sort of a fuzzy area in the spec, so any help would be appreciated.

When an xsl:element contains namespace declarations outside of the 'namespace' AVT, when should those namespace declarations be inserted into the result tree?

Here is an example of my problem:

<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; 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.

However, if I modify the stylesheet slightly...

<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; version="1.0">
  <xsl:template match="*">
    <out>
      <xsl:element name="a:foo" xmlns:a="bar">
        <child/>
      </xsl:element>
    </out>
  </xsl:template>
</xsl:stylesheet>

Xalan and Saxon both produces this:

<out><a:foo xmlns:a="bar"><child/></a:foo></out>

Clearly the 'bar' namespace belongs on the 'a:foo' result element., but this begs the question: How can this namespace be in scope for 'foo' depending on whether it is used or not?

In any other situation, a namespace enters scope once it is defined, regardless of how it is used.

Can anyone help clear this up?

-Jack Matheson

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



<Prev in Thread] Current Thread [Next in Thread>