Read XSLT 2.0 and XPath 2.0 Programmer's Reference, 4th Edition Online
Authors: Michael Kay
The use of positional predicates with the attribute axis doesn't make much sense, because the order of attributes is undefined (though I did see one stylesheet that was using
@*[1]
to match the first attribute, and
@*
—which has lower priority—to match the others, which is perfectly legitimate so long as you realize that it's unpredictable which of the attributes will be the first). In the following description, I'll assume that you're using the child axis.
If there is only one predicate in the
PatternStep
, or if this predicate is the first, then:
Note that it is the position of the node relative to its siblings that counts, not the position in the sequence you are processing the nodes. For example, suppose you want to process all the
Then suppose you have the following two template rules:
…
…
The first template rule will be used for any
…
…
This is because the context position within the body of the template rule is the position of the node in the list of nodes being processed, whereas the result for deciding whether a node matches a pattern is the same regardless of the processing context.
If there are several predicates in the
PatternStep
, then
position()
and
last()
in predicates after the first apply to the nodes that survived the previous predicates. So
speech[speaker= ’Hamlet’] [1]
matches a