Path, Predicates, and XQuery - More Complex Predicates (Page 2 of 6 )
So far, the examples of predicates have been simple path expressions, comparison expressions, and numbers. In fact, any expression is allowed in a predicate, making it a very flexible construct. For example, predicates can contain function calls, as in:
can be used to find all product elements whose third child element is colorChoices. The *[self::colorChoices] is part of a separate path expression that is itself within a predicate. * selects the third child element of product, and [self:: colorChoices] is a way of testing the name of the current context element.
Predicates are not limited to use with path expressions. They can be used with any sequence. For example:
(1 to 100)[. mod 5 = 0]
can be used to return the integers from 1 to 100 that are divisible by 5. Another example is:
which selects the price attribute if it exists, or the decimal value 0.0 otherwise.