Re: [xsl] ancestor::* and for-each

Subject: Re: [xsl] ancestor::* and for-each
From: Michael Kay <mike@xxxxxxxxxxxx>
Date: Thu, 29 Jul 2010 10:20:35 +0100
Just adding a little to what others have said on this.

This is undoubtedly one of the most confusing aspects of the XPath specification, and in my opinion it was not a good decision. The way the rules are expressed is different between XPath 1.0 and 2.0, because of the replacement of node-sets by sequences, but the effect is the same. Conceptually an AxisStep (of the form axis::nodetest[predicates]*) is evaluated in the following way:

1. All the nodes on the axis are selected, in axis order (that is, starting from the context node and moving outwards).

2. This sequence is filtered by retaining only the nodes that satisfy the nodetest

3. The sequence is then filtered using each of the predicates in turn. Within each predicate, position() refers to the position of a node in the sequence that results from the previous stage of filtering

4. The final filtered sequence is sorted into document order.

Apologies that "position" and "document" are trisyllabic, but I hope it explains what is going on.

Michael Kay
Saxonica


On 28/07/2010 17:11, Wolfgang Laun wrote:
I use ancestor-or-self::* to obtain the node sequence from some node
to the document root.
The outermost/top element of the document isn't interesting, so I add
a predicate, and I find that this works:
    [position() != last()]
Apparently, the sequence goes from leaf to root, which is the closing
tag order, as it should be.

Then, I iterate over the sequence, and now the nodes are processed
from root to leaf, which is strange.

There is a Note in Chapter 7, Repetion, that sounds as if it is
related to this, but, frankly, I don't understand it.
What does it mean, in monosyllabic words, please ;-)

I'm using this<xsl:stylesheet version="2.0">, and saxon9he.jar.

Thanks
-W

Current Thread