Read XSLT 2.0 and XPath 2.0 Programmer's Reference, 4th Edition Online
Authors: Michael Kay
An Informal Definition
Because they are written in terms of expressions, the formal rules for a pattern such as
book//para
, encourage you to think of the pattern as being evaluated from left to right, which means finding a
An alternative way of looking at the meaning of this expression, and the way in which most XSLT processors are likely to implement the pattern-matching algorithm, is to start from the right. The actual logic for testing a node against the pattern
book//para
is likely to be along the lines:
If there are predicates, these can be tested en route, for example to evaluate the pattern
speech [speaker = ’Hamlet’]
, the logic is likely to be the following:
Most patterns can thus be tested by looking only at the node itself and possibly its ancestors, its attributes, and its children. The patterns that are likely to be the most expensive to test are those that involve looking further afield.
For example, consider the pattern
para[last()-1]
, which matches any
para[1]
or
para[last()]
you've a slightly better chance that the processor will figure out a quicker way of doing the test, but it would be unwise to rely on it.