Predicates
Predicates are used in a path expression to filter the results to contain only nodes that meet specific criteria. Using a predicate, you can, for example, select only the elements that have a certain value for an attribute or child element, using a predicate like [@dept = "ACC"]. You can also select only elements that have a particular attribute child element, using a predicate such as [color], or elements that occur in a particular position within their parent, using a predicate such as [3].
The syntax of a predicate is simply an expression in square brackets ([ and ]). Table 4-6 shows some examples of predicates.
Table 4-6. Predicates (examples start with doc("catalog.xml")/catalog/)
|
Example |
Meaning |
|---|---|
|
|
All |
|
|
All |
|
|
All |
|
|
All |
|
|
All |
|
|
All |
If the expression evaluates to anything other than a number, its effective Boolean value is determined. This means that if it evaluates to the xs:boolean value false, the number 0 or NaN, a zero-length string, or the empty sequence, ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access