RE: [xsl] preceding sibling headaches

Subject: RE: [xsl] preceding sibling headaches
From: "Michael Kay" <mhk@xxxxxxxxx>
Date: Wed, 23 Apr 2003 08:49:09 +0100
> I thought that once you used a predicate ([1]), you couldn't go 
> any further in detail.

A lot of people imagine that. I've no idea why. Applying predicates to
intermediate steps in a path expression is one of the most powerful
techniques in XPath.

test="preceding-sibling::*[1]/self::transition" works as follows:

1. Select all the preceding sibling elements
2. Select the first of these
3. Select this node if it is a transition element, or nothing if not
4. Convert the result to a boolean: true if the node-set selected in (3)
is non-empty

I usually write this one as


but the result is the same.

Avoid tests like name()='transition' if you can. They are likely to be
more expensive, and are less resilient to your choice of namespace
prefixes in the source document. The only time to use them is when
testing against a variable, e.g. name()=$param, and ideally you should
then test local-name() and namespace-uri() rather than testing name().

Michael Kay
Software AG
home: Michael.H.Kay@xxxxxxxxxxxx
work: Michael.Kay@xxxxxxxxxxxxxx 

 XSL-List info and archive:

Current Thread