3.4 Booleans
Booleans
An object of type boolean can have one of two values, true and
false.
An or expression is evaluated by evaluating each
operand and converting its value to a boolean as if by a call to the
boolean function. The result is true if either
value is true and false otherwise. The right operand is not evaluated
if the left operand evaluates to true.
An and expression is evaluated by evaluating each
operand and converting its value to a boolean as if by a call to the
boolean function. The result is true if both
values are true and false otherwise. The right operand is not
evaluated if the left operand evaluates to false.
An
[EqualityExpr]
(that is not just
a
[RelationalExpr]
) or a
[RelationalExpr]
(that is not just an
[AdditiveExpr]
) is evaluated by comparing the
objects that result from evaluating the two operands. Comparison of
the resulting objects is defined in the following three paragraphs.
First, comparisons that involve node-sets are defined in terms of
comparisons that do not involve node-sets; this is defined uniformly
for =, !=, <=,
<, >= and >. Second,
comparisons that do not involve node-sets are defined for
= and !=. Third, comparisons that do not
involve node-sets are defined for <=,
<, >= and >.
If both objects to be compared are node-sets, then the comparison
will be true if and only if there is a node in the first node-set and
a node in the second node-set such that the result of performing the
comparison on the
[string-value]
s of the two nodes is
true. If one object to be compared is a node-set and the other is a
number, then the comparison will be true if and only if there is a
node in the node-set such that the result of performing the comparison
on the number to be compared and on the result of converting the
[string-value]
of that node to
a number using the number function is true. If
one object to be compared is a node-set and the other is a string,
then the comparison will be true if and only if there is a node in the
node-set such that the result of performing the comparison on the
[string-value]
of the node and
the other string is true. If one object to be compared is a node-set
and the other is a boolean, then the comparison will be true if and
only if the result of performing the comparison on the boolean and on
the result of converting the node-set to a boolean using the
boolean function is true.
When neither object to be compared is a node-set and the operator
is = or !=, then the objects are compared by
converting them to a common type as follows and then comparing them.
If at least one object to be compared is a boolean, then each object
to be compared is converted to a boolean as if by applying the
boolean function. Otherwise, if at least one
object to be compared is a number, then each object to be compared is
converted to a number as if by applying the
number function. Otherwise, both objects to be
compared are converted to strings as if by applying the
string function. The = comparison
will be true if and only if the objects are equal; the !=
comparison will be true if and only if the objects are not equal.
Numbers are compared for equality according to IEEE 754 IEEE754. Two booleans are equal if either both are true or
both are false. Two strings are equal if and only if they consist of
the same sequence of UCS characters.
NOTE:
If $x is bound to a node-set, then
$x="foo" does not mean the same as
not($x!="foo"): the former is true if and only if
some node in $x has the string-value
foo; the latter is true if and only if all
nodes in $x have the string-value
foo.
When neither object to be compared is a node-set and the operator
is <=, <, >= or
>, then the objects are compared by converting both
objects to numbers and comparing the numbers according to IEEE 754.
The < comparison will be true if and only if the first
number is less than the second number. The <=
comparison will be true if and only if the first number is less than
or equal to the second number. The > comparison will
be true if and only if the first number is greater than the second
number. The >= comparison will be true if and only if
the first number is greater than or equal to the second number.
NOTE:
When an XPath expression occurs in an XML document, any
< and <= operators must be quoted
according to XML 1.0 rules by using, for example,
< and <=. In the following
example the value of the test attribute is an XPath
expression:
<xsl:if test="@value < 10">...</xsl:if>
NOTE:
The effect of the above grammar is that the order of
precedence is (lowest precedence first):
-
or
-
and
-
=, !=
-
<=, <, >=,
>
and the operators are all left associative.
For example, 3 > 2 > 1 is equivalent to (3
> 2) > 1, which evaluates to false.
|