Re: [xsl] Unexpected Context Node at Points in XPath Expression

Subject: Re: [xsl] Unexpected Context Node at Points in XPath Expression
From: Abel Braaksma <>
Date: Wed, 05 Sep 2007 01:59:57 +0200
Michael Terry wrote:
I think I misunderstood what becomes the context node. Take the first
one I mentioned:

- count(preceding-sibling::*)]

I thought that while the position() filter was running, 'h2[1]' would
be the context node. Instead, it seems the result of
'following-sibling::*' is the context node? What, does it change the
context node to each item in that set as it applies the filter? I
don't suppose there's a way to refer to the previous context node in a
relative way, is there?

In XSLT 2.0 there are a couple of provisions that make it a bit easier to create an XPath. But in 1.0, it is just about what you say: the context node at any given point is the one that is selected. How would you know whether it needs the position() of first element, the second, the third? You can use, however, a predicate, which translates freely like "having" in SQL. In this case, the contextnode is the one that the predicate is making a selection about.

following has context node * for position()
a/b/c/*[position() = 2]

following has context node c for position()
a/b/c[position() = 2]/*

following has context node a for position(), but beware, it is in the third predicate, so it counts only the subset selected by the earlier predicates.
a[count(b/c/*) = '12'][b[@x = 'rr']][position() = 2]


-- Abel Braaksma

Current Thread