Section 17.5.  Predicates

Prev don't be afraid of buying books Next

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> 

Amazon


XML in Office 2003. Information Sharing with Desktop XML
XML in Office 2003: Information Sharing with Desktop XML
ISBN: 013142193X
EAN: 2147483647
Year: 2003
Pages: 176

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net