Node comparisons
Node comparisons compare two nodes. Nodes can be compared to determine if they share the same identity or if one node precedes or follows another node in document order.
The following table describes the node comparison operators
that are available in XQuery.
Operator | Purpose |
---|---|
is | Returns true if the two nodes that are compared have the same identity. |
<< | Returns true if the first operand node precedes the second operand node in document order. |
>> | Returns true if the first operand node follows the second operand node in document order. |
Restriction: The operand of a
node comparison cannot contain an FLWOR expression.
The
result of a node comparison is either a Boolean value, an empty sequence,
or an error. The result of a node comparison is defined by the following
rules:
- Each operand must be either a single node or an empty sequence; otherwise, an error is returned.
- If either operand is an empty sequence, the result of the comparison is an empty sequence.
- A comparison that uses the is operator is true when the two nodes that are compared have the same identity; otherwise, the comparison is false.
- A comparison that uses the << operator returns true when the left operand node precedes the right operand node in document order; otherwise, the comparison returns false. If the nodes are from two different documents, the document ID determines the precedence.
- A comparison that uses the >> operator returns true when the left operand node follows the right operand node in document order; otherwise, the comparison returns false. If the nodes are from two different documents, the document ID determines the precedence.
Examples
- The following comparison is true only if both the left operand
and right operand evaluate to exactly the same single node:
/books/book[isbn="1558604820"] is /books/book[call="QA76.9 C3845"]
- The following comparison is false because each constructed node
has its own identity:
<a>5</a> is <a>5</a>
- The following comparison is true only if the node that is identified
by the left operand occurs before the node that is identified by the
right operand in document order:
/transactions/purchase[parcel="28-451"] << /transactions/sale[parcel="33-870"]