Read XSLT 2.0 and XPath 2.0 Programmer's Reference, 4th Edition Online
Authors: Michael Kay
The
position()
and
last()
functions relate to children of the same parent even when the
//
operator is used. For example,
chapter//footnote[1]
matches any
footnote
element that is a descendant of a
footnote
child of its parent. There is no simple way to write a pattern that matches the first
footnote
element in a
(chapter//footnote)[1]
is not a valid pattern. (Why not? No good reason, it's just that the spec doesn't allow it.)
If you do need to write a template rule for the first
match=“footnote[test:position-in-chapter(.) = 1]”
. The definition of the function might look like this.
Examples
The following table provides some examples of
PatternSteps
.
Construct | Meaning |
child::title | Matches elements named |
title | Short form of child::title . |
attribute::title | Matches attributes named |
@title | Short form of attribute::title . |
*[@width] | Matches an element node that has an attribute named width . |
text()[starts-with(.,’The’)] | Matches a text node whose text content starts with the characters The . |
p[@code][position() lt 10] | Matches a code attribute. |
p[position() lt 10][@code] | Matches a code attribute. |
*[not(@code = preceding-sibling::*/@code)] | Matches an element node provided that it does not have a code attribute with the same value as the code attribute of any preceding sibling element. |
comment() | Matches any comment node. |
@comment() | Matches comment nodes that are found on the attribute axis of their parent node. Because the attribute axis contains attribute nodes only, this condition can never be satisfied; nevertheless, it is a legal PatternStep . |