Predicates

A predicate consists of an expression, called a predicate expression, that is enclosed in square brackets ([]). A predicate filters a sequence by retaining some items and discarding others.

The predicate expression is evaluated once for each item in the sequence. The result of the predicate expression is an xs:boolean value called the predicate truth value. Those items for which the predicate truth value is true are retained, and those for which the predicate truth value is false are discarded. The value of the predicate expression must not be a numeric value. For all other data types, the predicate truth value is the effective boolean value of the predicate expression. The effective boolean value is false if the predicate expression evaluates to an empty sequence or false. Otherwise, the effective boolean value is true.

Examples

The following examples are axis steps that include predicates:
  • descendant::phone[attribute::type = "work"] selects all the descendants of the context node that are elements named phone and whose type attribute has the value "work".
  • child::address[prov-state][pcode-zip] selects all the address children of the context node that have a prov-state child element and a pcode-zip child element.