Re: Namespace nodes in XSLT and XPath

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=""><foo/></out>
  <out xmlns=""><foo xmlns=""/></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.

 <xsl:stylesheet version="1.0" xmlns:xsl="">
   <xsl:template match="/">
       <out xmlns="" xmlns:bar="">
           <xsl:element name="foo" namespace=""/>

Does this result in a Result Tree corresponding to:
  <out xmlns="" xmlns:bar="">
or to:
  <out xmlns="" xmlns:bar="">
  <foo xmlns=""/>
(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 --
followed by
per document order.  But in the latter alternative, the namespace
nodes associated with the element 'foo' are:
followed by
 -- the {} namespace node is drawn from the 'foo'
element, not from the 'out' element, and therefore should be ordered
after the {} 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.


Received on Wednesday, 28 June 2000 20:50:49 UTC