XML technologies / XPath / XPath introduction / Boolean operators & Cascading predicates

 

Boolean operators in predicates

Predicates may contain the Boolean operators "and" and "or".

//TITLE[@style="Pop" and @evaluation=4]

Selection of all "TITLE" elements which have a "style" attribute, which has the value "Pop" and at the same time an "evaluation" attribute with the value 4.

//TITLE[@style="Pop" or @evaluation > 2]

Selection of all "TITLE" elements which have a "style" attribute, which has the value "Pop" or an "evaluation" attribute with a value greater than 2.

Cascading predicates

Apart from the Boolean operators, predicates can be cascaded. A cascade of predicates can be described as a series connection of filters. At first, a node volume is filtered. The result is at the same time the initial volume for the second predicate and so on.

//section[para][@type='warning']

At first, all "section" elements are selected. The first predicate only keeps those elements having a "para" child element. This result volume is filtered again. Only those elements remain whose "type" attribute has the value "warning".

 

back to top