All elements that have a specified attribute
All elements that have a specified attribute with a specified value
The first element that contains a specified child element
An element whose text content includes a specified string
All elements that are not the first or last children of their parents
All elements whose value is a number
All elements whose value is a number greater than 100
These are just a small sampling of the selections that predicates make possible.
XPointer predicate expressions do have one small distinction from the expressions used in XSLT. The result of an XPointer predicate expression is ultimately converted to a boolean after all calculations are finished. Non-boolean results are converted as follows:
A number is false if it's zero or NaN (a special symbol meaning "Not a Number", used for the result of dividing by zero and similar illegal operations), true otherwise.
An empty node set is false; all other node sets are true.
An empty result fragment is false; all other result fragments are true.
A zero length string is false; all other strings are true (including the string "false")
The predicate expression is evaluated for each node in the context node list. Each node for which the expression ultimately evaluates to false is removed from the list. Thus only those nodes that satisfy the predicate remain. I will not repeat here the discussion of the operators and functions available to use expressions. However, I will show you a few examples of predicates using the expression syntax as it's likely to be used in XPointers.
Probably the function most frequently used in XPointer
predicates is position()
. This returns the index of
the node in the context node list. This allows you to find the
first, second, third, or other indexed node. You can compare
positions using the various relational operators like
<
, >
, =
,
!=
, >=
, and <=
.
xpointer(/child::FAMILYTREExpointer(/child::*[position()=1])
xpointer(/child::FAMILYTREExpointer(/child::*[position()=2])
xpointer(/child::FAMILYTREExpointer(/child::*[position()=3])
xpointer(/child::FAMILYTREExpointer(/child::*[position()=4])
xpointer(/child::FAMILYTREExpointer(/child::*[position()=5])
xpointer(/child::FAMILYTREExpointer(/child::*[position()=6])
xpointer(/child::FAMILYTREExpointer(/child::*[position()=7])
xpointer(/child::FAMILYTREExpointer(/child::*[position()=8])
xpointer(/child::FAMILYTREExpointer(/child::*[position()=9])
xpointer(/child::FAMILYTREExpointer(/child::*[position()=10])
xpointer(/child::FAMILYTREExpointer(/child::*[position()=11])
xpointer(/child::FAMILYTREExpointer(/child::*[position()=12])
xpointer(/child::FAMILYTREExpointer(/child::*[position()=13])
xpointer(/child::FAMILYTREExpointer(/child::*[position()=14])