Restrict item sequence to those matching one or more predicates.
In a step expression, StepQualifiers
can be used to restrict
the current sequence of items with the help of one or more predicate
expressions each of which is enclosed in brackets. If you specify more than one
step qualifier, their order has no effect on the result except if you use
numeric predicates.
The predicate expression can be either a Boolean or a numeric expression.
A numeric predicate [n]
is short for
[position()=n]
which is true for all
nodes that are the nth child element in the input
node sequence. If the type of the predicate expression is not numeric, then it
is treated as a Boolean expression.
Select all books published by one or more editors before 2000:
input()//book[editor][@year < 2000]
The sequence of all book
elements in the
current collection is filtered by two consecutive step qualifiers: the first
predicate expression is true for all book
elements
that have a child element editor
, which means that
all book
elements with a child element
author
are filtered out. The retained node sequence
is then checked for the second predicate. Note that the context node is still
book
and not editor
so
the path expression looks for an attribute year
of the book
element to see if its value is less than
2000.
Select the third book:
input()//book[3]
This query is short for input()//book[position() = 3]
.
From all book
elements the one that is the third
child element of its parent is retained.
The following construct(s) refer to this construct:
This construct is also related to the following construct(s):
StepExpr
|