
250 • XML & Related Technologies
6.3.4 Using Predicates
So far, we have limited our discussions to the axes and node tests. We will now look at the third aspect of a
location path: predicates.
Predicate provide us fine-grained control over the nodes to be selected. They are contained inside square
brackets. For example, consider the following XPath expression:
child::COMMENT [position ( ) = 1]
This allows us to select the first <COMMENT> element child of the context node. For this, we make use
of the position ( ) function.
A predicate can return multiple nodes. For example, consider the following predicate:
child::COMMENT [position ( ) > 1]