Re: [xsl] the nearest ancestor with the attribute

Subject: Re: [xsl] the nearest ancestor with the attribute
From: Jeni Tennison <mail@xxxxxxxxxxxxxxxx>
Date: Thu, 18 Jan 2001 13:07:28 +0000
Since I started this confusion in the first place, can I summarise and
check that I've got it right now?

A node set is always unordered until you do anything with it like
iterate over it, get a value from it or whatever. Of course a node set
is pretty useless unless you do something with it, so saying a node
set is unordered doesn't particularly help :)

When you use a node set to do something with nodes within an XSLT
attribute (e.g. xsl:value-of/@select or xsl:apply-templates/@select or
xsl:for-each/@select) then the node set is always sorted into
*document order* no matter what axes you use.

When you use a predicate on a node set that's already been generated,
such as a node-set variable, a union or just by putting brackets
around it (e.g. $foo[1], (//*/@*)[1] or (foo|bar)[1]) then the node
set is always sorted into *document order* no matter what axes you
use.

When you use a predicate on a node set within a step (e.g. //*/@*[1]
or foo[1]) then the node set is sorted according to the axis. If it's
preceding::, preceding-sibling::, ancestor:: or ancestor-or-self::
then it's a reverse axis, otherwise it's a forward axis. If it's a
reverse axis, then it's sorted into *reverse document order* before
the predicate is assessed; if it's a forward axis, then it's sorted
into *document order* before the predicate is assessed.

Having said all that, the attribute:: axis and the namespace:: axis
are a bit weird because there is no real concept of 'document
order' for attributes or namespace nodes. So, although @*[1] gives you
the first attribute in document order, this could actually be any
attribute on the element. It rarely makes sense to use a positional
predicate with an attribute or namespace axis because attributes and
namespaces have no inherent position in an element. For attributes
and namespaces, document order is implementation dependent: it's
fairly likely (?) that they'll just be sorted alphabetically.
Namespace nodes always come before attribute nodes, though, and both
occur before any child nodes.

Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/



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


Current Thread