W3C home > Mailing lists > Public > xsl-editors@w3.org > April to June 2000

Re: Namespace nodes in XSLT and XPath

From: Michael Fuller <msf@mds.rmit.edu.au>
Date: Thu, 29 Jun 2000 10:50:21 +1000
To: David Carlisle <davidc@nag.co.uk>
Cc: xsl-list@mulberrytech.com, xsl-editors@w3.org
Message-ID: <20000629105021.A7886@io.mds.rmit.edu.au>
On Wed, Jun 28, 2000 at 11:40:48AM +0100, David Carlisle wrote:

[taking your second comment first...]
> as is the case for attribute nodes, an implementation has to order
> namespace nodes, but the ordering is implementation specific,
> so you might get either one.

Where does XSLT/Xpath allow that the ordering of namespace nodes in the
result tree (as opposed to the output document) is implementation specific?

XPath 2.4 "Predicates" states that "[a]n axis is either a forward axis
or a reverse axis", and that axes other than ancestor, ancestor-or-self,
preceding, and preceding-sibling are forward axes.

So the ordering of namespace nodes in the result tree is explicitly
specific; this is also true for the attribute axis. (As you point
out below, XSLT 16.1 does indeed allow that the ordering of attributes
in an linearized XML document may vary.)

[which takes us back to...]
> Actually they are equivalent as namespace nodes do not correspond to
> explicit namespace declarations in the source file, they are copied
> to all descendent nodes while the input tree is being constructed.

Yes, you're right in the case of:
  <out xmlns="http://www.foo.com/"><foo/></out>
versus
  <out xmlns="http://www.foo.com/"><foo xmlns="http://www.foo.com/"/></out>
because only one occurence of the default 'xmlns' namespace is included in
the set of namespace nodes, per XPath 5.4. Sorry, the example was inadequate.

Consider:
 <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
   <xsl:template match="/">
       <out xmlns="http://www.foo.com/" xmlns:bar="http://www.bar.com">
           <xsl:element name="foo" namespace="http://www.foo.com/"/>
       </out>
   </xsl:template>
 </xsl:stylesheet>

Does this result in a Result Tree corresponding to:
  <out xmlns="http://www.foo.com/" xmlns:bar="http://www.bar.com">
  <foo/>
  </out>
or to:
  <out xmlns="http://www.foo.com/" xmlns:bar="http://www.bar.com">
  <foo xmlns="http://www.foo.com/"/>
  </out>
(I'm thinking about the result trees, not the linearized XML output
shown here.)

Are these equivalent? Given that the namespace axis is ordered per
XSLT 2.4 (proximity position for forward axes), the namespace nodes
associated with element 'foo' are -- in the former alternative --
    {http://www.foo.com/}
followed by
    {http://www.bar.com}
per document order.  But in the latter alternative, the namespace
nodes associated with the element 'foo' are:
    {http://www.bar.com}
followed by
    {http://www.foo.com/}
 -- the {http://www.foo.com/} namespace node is drawn from the 'foo'
element, not from the 'out' element, and therefore should be ordered
after the {http://www.bar.com} namespace node.


[re. pasting RTFs into result trees, and its effect on namespaces]
> Note that if the namespace declaration is higher up the document then
> parsing the linearised document will produce a different tree than the
> original result tree (less namespace declarations implies more namespace
> nodes, usually)
>
> but this is explicitly allowed by xslt 16.1:
[...]
>         The new tree may contain namespace nodes that were not present
>         in the result tree.

Ah, of course. This caveat makes all the difference. Thank you!

> David
> [I should stress that I am answering from xsl-list not xsl-editors,
>  as you cross posted]

Thank you.

Michael
Received on Wednesday, 28 June 2000 20:50:49 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Monday, 7 December 2009 10:59:50 GMT