January 2002
Intermediate to advanced
480 pages
11h 5m
English
As well as Boolean expressions, predicates can contain numerical expressions.
foo[5] foo[last()]
These predicates match elements based on their document order in the node set.
Imagine this source document:
<person>
<name>Mr. Fish</name>
<address>The Sea</address>
<appearance>Shiny and scaly</appearance>
<person> This expression produces a node set with three element nodes:
/person/*
You can use a positional predicate on that node set to pull out the second node within it in document order:
/person/*[2]
The result will be a node set containing just one node, the element <address>.
A more complex example would be to select the first <img> element in an XHTML document:
//img[1]
The expression //img matches all