XSLT 2.0 and XPath 2.0 Programmer's Reference, 4th Edition (450 page)

BOOK: XSLT 2.0 and XPath 2.0 Programmer's Reference, 4th Edition
3.75Mb size Format: txt, pdf, ePub

keyword can use all variables declared in previous clauses of the expression (but not the variable ranging over that expression itself).

For example:

some $p in //price satisfies $p > 10000

is true if there is a

element in the document whose typed value is a number greater than 10,000, while:

every $p in //price satisfies $p > 10000

is true if every

element in the document has a typed value greater than 10,000.

The result of the expression (unless some error occurs) is always a single
xs:boolean
value.

The
satisfies
expression is evaluated to return a boolean value. This evaluation returns the
effective boolean value
of the expression, using the same rules as for the
boolean()
function and the condition in an
if
expression. For example, if the result of the expression is a string, the effective boolean value is
true
if the string is not zero-length. The expression will almost invariably reference each one of the range variables, although the results are still well defined if it doesn't.

As with
for
expressions,
some
and
every
expressions do not change the context item. This means that the following is wrong (it's not an error, but it doesn't produce the intended answer):

(:wrong:) some $i in //item satisfies price > 200

It should be written instead:

(:correct:) some $i in //item satisfies $i/price > 200

Note that if the input sequence is empty, the
some
expression will always be
false
, while the
every
expression will always be
true
. This may not be intuitive to everyone, but it is logical—the
every
expression is true if there are no counter-examples; for example, it's true that every unicorn has one horn, because there are no unicorns that don't have one horn. Equally, and this is where the surprise comes, it is also true that every unicorn has two horns.

Other books

To Serve Is Divine by R. E. Hargrave
My Beautiful Hippie by Janet Nichols Lynch
Hot at Last by Cheryl Dragon
The Hairball of Horror! by Michael Broad
Open Shutters by Mary Jo Salter