XML technologies / XPath / XPath 2.0: language reference / XPath expressions: operators and keywords / Logical combinations of expressions
(Excerpt from "XSLT 2.0 & XPath 2.0" by Frank Bongers, chapter 4.)
Operators: and, or
XPath combines two expressions logically using AND or OR. The logical operators are and and or. A combination using and has precedence over one using or when both operators occur in a larger expression.
Each operand is evaluated in a Boolean context and contributes its effective Boolean value to the whole expression. Unless an error occurs, the result is therefore always true or false.
The logical expression A1 and A2 is true when both operands’ effective Boolean values, A1 and A2, are true. The logical expression A1 or A2 is true when one or both operands’ effective Boolean values are true.
Operands are automatically converted to their effective Boolean values when the whole expression is normalized according to fn:boolean(). The logical operator is then applied:
a and b
is therefore essentially equivalent to
fn:boolean(a) and fn:boolean(b)
Both following expressions return true:
1 eq 1 and 2 ne 3
1 eq 1 or 2 ne 2
Combined with fn:not(), which returns the logical negation of its argument’s effective Boolean value, all logical combinations of two expressions can be represented:
AND: a and b
OR: a or b
NAND: fn:not(a and b)
NOR: fn:not(a or b)
Looking back at XPath 1.0
There are no differences here: the logical operators and and or are implemented in the same way in XPath 1.0 and XPath 2.0.
Copyright © Galileo Press, Bonn 2008
You may print the online version for private use.
Otherwise, this chapter from "XSLT 2.0 & XPath 2.0 ― Das umfassende Handbuch" is subject to the same terms as the bound edition: the work and all its parts are protected by copyright. All rights reserved, including reproduction, translation, microfilming, storage and processing in electronic systems.
Galileo Press, Rheinwerkallee 4, 53227 Bonn