17.5. Predicates A predicate is an expression that changes the group of objects addressed by another expression that precedes it. A predicate expression is delimited by square brackets and is either true or false. If true, it adds to the objects addressed; if false, it removes objects. For example, the expression in Example 17-7 addresses all chapters that have a figure element in them. Example 17-7. Addressing chapters with a figure element /book/chapter[figure] The predicate expression figure is true for any chapter that contains a figure. If true, that chapter is included among the addressed objects. Note that the figure itself is not among the objects addressed (although it is contained within the addressed chapter object). A predicate expression can be a comparison. For example, .= lets you address an element by comparing its content data to a specific character string. Example 17-8 uses this technique to address all the par elements that have "Second paragraph". as their content data. Example 17-8. Addressing par elements with specific content data /book//par[.="Second paragraph."] Example 17-9. Objects addressed by Example 17-8 <par author="cg">Second paragraph.</par> |