The final possible component of an XPath location step, called the predicate, provides a further, finer-grained filter to select among the node(s) located by the node-test and axis. The basic form of a predicate is:
[something operator somevalue]
where:
For instance:
[position() = 1]
locates the first matching node in document order, while:
[attribute::empid != "73519"]
locates the subset of the matching node-set at that point which includes any nodes with an empid
attribute whose string value does not equal "73519".
Note Be careful when using the "<" and ">" operators in your XPath expressions. Because these characters are significant in markup, you will typically have to escape them using the<
and>
entity references. For example:
[attribute::empid <= "69999"]
says to select all nodes with an empid
attribute whose value is <= (less than or equal to) "69999".
White space between the terms of a predicate is not significant. That is:
[position() = 1]
and
[position()=1]
function identically.
Filtering XML Data Using XPath Predicates