home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam  


Book HomeXSLSearch this book

B.4. XPath Operators

All operators defined by XPath are listed here.

B.4.2. Boolean Operators

=
Tests whether two expressions are equal.

<
Tests whether the first expression is less than the second. Within an attribute, this operator must be coded &lt;.

<=
Tests whether the first expression is less than or equal to the second. Within an attribute, this operator must be coded &lt;=.

>
Tests whether the first expression is greater than the second. Within an attribute, this operator can be coded &gt;.

>=
Tests whether the first expression is greater than or equal to the second. Within an attribute, this operator can be coded &gt;=.

!=
Tests whether the two expressions are not equal.

and
Tests whether both the first and second expressions are true. If the first expression is false, the second is not evaluated.

or
Tests whether either the first or second expressions are true. If the first expression is true, the second is not evaluated.

B.4.2.1. Comparing values of various datatypes

For the first six boolean operators, comparing values of various datatypes is complicated. We explain the various possibilities here:

If both objects are boolean values
Then they are equal if they have the same value. For less-than and greater-than comparisons, false is considered less than true (the function call number(false()) returns 0, while number(true()) returns 1).

If both objects are numbers
Then the operators work just the way you'd think they would.

If both objects are strings
Then they are equal if their Unicode characters are identical. For less-than and greater-than comparisons, the character codes are compared.

If neither object is a node-set and the operator is = or !=
Then the two objects are converted to the same object type, and the comparison works as described previously. If one of the objects is a boolean, then the objects are converted to boolean values as if by a call to the boolean() function. If none of the objects are boolean, the next attempted conversion is to a number. If one of the objects is a number, then the objects are converted to numeric values as if by a call to the number() function. Otherwise, all objects are converted to strings as if by a call to the string() function.

If neither object is a node-set and the operator is <, >, or >=
Then the objects are converted to numbers and compared.

If one or both of the objects is a node-set
Then things really get complicated. If both objects are node-sets, a comparison is true when the string value of at least one node in the first node-set is equal to the string value of at least one node in the second node-set. If one object is a node-set and the other is a number, string, or boolean, the comparison is true when there is at least one node in the node set whose number, string, or boolean value is equal to that number, string, or boolean value.



Library Navigation Links

Copyright © 2002 O'Reilly & Associates. All rights reserved.