Read XSLT 2.0 and XPath 2.0 Programmer's Reference, 4th Edition Online
Authors: Michael Kay
some $s in $S, $t in $T, $u in $U satisfies CONDITION
has exactly the same effect as the expression:
exists(for $s in $S, $t in $T, $u in $U return boolean(CONDITION)[.])
while the expression:
every $s in $S, $t in $T, $u in $U satisfies CONDITION
has exactly the same effect as the expression:
empty(for $s in $S, $t in $T, $u in $U return not(CONDITION)[.])
The rather unusual predicate
[.]
selects all the items in a sequence whose effective boolean value is true. In the first case, the result is
true
if the result of the
for
expression contains at least one value that is
true
, while in the second case, the result is
true
if the result of the
for
expression contains no value that is
false
.
(The functions
exists()
and
empty()
are described in Chapter 13. The
exists()
function returns true if the supplied sequence contains one or more items, while
empty()
returns true if the sequence contains no items.)
Examples
Expression | Description |
some $i in //item satisfies $i/price gt 200 | Returns true if the current document contains an |
some $n in 1 to count($S)-1 satisfies $S[$n] eq $S[$n + 1] | Returns true if there are two adjacent values in the input sequence $S that are equal. |
every $p in //person satisfies $p/@dob castable as xs:date | Returns true if every dob attribute that represents a valid date, according to the XML Schema format YYYY-MM-DD . |
some $k in //keyword, $p in //para satisfies contains($p, $k) | Returns true if there is at least one |
every $d in //termdef/@id satisfies some $r in //termref satisfies $d eq $r/@def | Returns true if every id attribute is referenced by at least one def attribute. |
Quantification and the
=
Operator
An alternative to using the
some
expression (and sometimes also the
every
expression) is to rely on the implicit semantics of the
=
operator, and other operators in the same family, when they are used to compare sequences. As we saw in Chapter 8, these operators can be used to compare two sequences, and return
true
if any pair of items (one from each sequence) satisfies the equality condition.