|
Home > Online Product Documentation > Table of Contents > Comparing Values Comparing Values
In queries, you can specify operators that compare values. Comparison operations return Boolean values. If you want to obtain the nodes for which a comparison tests
This section discusses the following topics: About Comparison OperatorsThe comparison operators you can specify are listed in Table 63:
You can specify single or double quotation marks (' or ") as string delimiters in expressions. This makes it easier to construct and pass queries from within scripting languages. How the XPath Processor Evaluates ComparisonsA query can compare values of elements. For example:
The XPath processor compares the value of each
As mentioned before in
Filtering Results of Queries, the XPath processor evaluates filters with respect to a context. For example, the expression
Comparisons are case sensitive. For example,
Remember that comparisons return Boolean values. For example:
You might think that this query returns authors whose last name is
To obtain
Comparing Node SetsYou can compare Two Node Sets
Suppose the objects you want to compare are both node sets. The result is true only in the following case. There is a node in the first node set and a node in the second node set such that the result of performing a comparison on the values of the two nodes is
A Node Set and a Number
Now suppose one object to be compared is a node set and the other is a number. The XPath processor searches for a node in the node set that yields a true result when its number value is compared with the number that is not in the node set. If necessary, the XPath processor uses the
A Node Set and a String
Sometimes you want to compare a node set with a string. The XPath processor searches for a node in the node set that yields a true result when its string value is compared with the string that is not in the node set. If necessary, the XPath processor uses the
A Node Set and a Boolean Value
Finally, suppose you want to compare a node set with a Boolean value. This tests true if and only if the result of performing the comparison on the Boolean value and on the result of converting the node set to a Boolean value using the
Comparing Single Values With = and !=
When neither object to be compared is a node set and the operator is
If the objects to be compared are neither Boolean nor numeric, the XPath processor compares the string values of the objects as if by applying the
The
Comparing Single Values With <=, <, >, and >=
When neither object to be compared is a node set and the operator is
The XPath processor always evaluates these comparisons in terms of numbers. You cannot use the less than and greater than operators to order strings. This is especially important to remember when you compare a number with a string. For example, suppose you want to evaluate the expression
The return value is always
Priority of Object Types in ComparisonsWhen the XPath processor performs a comparison, if either operand is a Boolean value, the XPath processor automatically converts the other operand to a Boolean value, if necessary, and makes a Boolean comparison. If either operand is numeric and neither operand is Boolean, the XPath processor automatically converts the other operand to a numeric value, if necessary, and performs a numeric comparison. If neither operand is numeric or Boolean, the XPath processor performs a string comparison. Examples of ComparisonsThe following query finds all authors whose last name is Bob:
The next query finds authors whose degrees are not from Harvard:
The following query returns prices that are greater than 20 dollars. This assumes that the current context contains one or more
Operating on Boolean Values
You can use the
|

Cart

