|
THE XML REVOLUTION - TECHNOLOGIES FOR THE FUTURE WEB
|
|
Predicates
- expressions coerced to type boolean
A predicate filters a node-set by evaluating the predicate expression
on each node in the set with
- that node as the context node,
- the size of the node-set as the context size, and
- the position of the node in the node-set wrt. the axis ordering as
the context position.
Example:
child::section[position()<6] / descendant::cite[attribute::href="there"]
|
selects all cite elements with href="there"
attributes in the first 5 sections of an article document.
(Compare with the earlier example.)
The XPath predicate language is very large, but these are
the essential ones to know
- [attribute::name="flour"]: test equality of an attribute
- [attribute::name!="flour"]: test inequality of an attribute
- [attribute::amount='0.5' and attribute::unit='cup']: test two things
at once (also or)
- [position()=2]: test position among siblings
- [attribute::amount<'0.5']: a syntax error
- [attribute::amount<'0.5']: a useless
test of lexicographical order
- [number(attribute::amount)<number('0.5')]:
what you meant to write instead!
An entire location path may be used as a predicate
- start at the current node
- the predicate is true if the
location path hits some result positions
- it is false otherwise
This is very useful to look ahead:
- [attribute::amount]:
the node has an amount attribute
- [descendant::ingredient]: the
node has a nested ingredient
|
COPYRIGHT © 2000-2003
ANDERS MØLLER & MICHAEL I. SCHWARTZBACH
|
|