XPath provides several boolean operators. They’re all straightforward (in XPath 1.0, anyway), so we’ll just list them here.

When you’re working with boolean expressions in XPath,
remember that the values `'true'`

and `'false'`

are just
strings. If you need to use the boolean values, use the
functions `true()`

and `false()`

. Simply using `true`

in an XPath expression means a node
whose name is `true`

, which is
almost certainly not what you want. To emphasize the point, we’ll
refer to the boolean values with their functions.

As we saw in the section on mathematical operators, converting
`true()`

and `false()`

to numbers
returns `1`

and `0`

, respectively. XPath defines rules for
converting different datatypes to boolean values. See Converting to boolean values” in Chapter 5
for all the details.

There are several operators from XPath 1.0 (and 2.0) that compare expressions. We’ll look at those here:

`=`

(equal)Given two expressions, returns

`true()`

if the two expressions evaluate to the same value, and returns`false()`

otherwise.`!=`

(not equal)Given two expressions, returns

`true()`

if the two expressions do not evaluate to the same value, and returns`false()`

otherwise.`<`

or`<`

(less than)Given two expressions, returns

`true()`

if the first expression evaluates to a value less than the second. Otherwise, it returns`false()`

. The less than operator is usually escaped with`<`

so that it doesn’t look like the opening arrow of an XML tag.`<=`

or`<=`

(less than or equal)Given ...

Start Free Trial

No credit card required