O'Reilly logo

XSLT, 2nd Edition by Doug Tidwell

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Boolean Operators

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

Note

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.

Comparing expressions

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 &lt; (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 &lt; so that it doesn’t look like the opening arrow of an XML tag.

<= or &lt;= (less than or equal)

Given ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required