Comparisons

The simplest comparison operators are eq, ne, lt, le, gt, and ge. These compare two atomic items of the same type, for example two integers, two dates, or two strings. In the case of strings, the default collation is used (this can be set using the configuration property DEFAULT_COLLATION). If the operands are not atomic items, an error is raised.

The operators =, !=, <, <=, >, and >= can compare arbitrary sequences. The result is true if any pair of items from the two sequences has the specified relationship, for example $A = $B is true if there is an item in $A that is equal to some item in $B. If an argument is a node, the effect depends on whether the source document has been validated against a schema. In Saxon-EE, with a validated source document, Saxon will use the typed value of the node in the comparison. Without schema validation, the type of the node is untypedAtomic, and the effect is that the value is converted to the type of the other operand.

The operator is tests whether the operands represent the same (identical) node. For example, title[1] is *[@note][1] is true if the first title child is the first child element that has a note attribute. If either operand is an empty sequence the result is an empty sequence (which will usually be treated as false).

The operators << and >> test whether one node precedes or follows another in document order.

From XPath 4.0:

  • The non-ASCII characters and (xFF1C and xFF1E) can be used in place of < and > to represent the less-than and greater-than operators; these characters can also be used in place of < and > in the compound tokens <=, >=, <<, >>, =>, ->, and =!>. (Implemented from Saxon 12.3.)

  • New node comparison operators are introduced: is-not can be used as a complement to the operator is; precedes and follows can be used as synonyms for the existing operators << and >>; precedes-or-is and follows-or-is can be used as synonyms for the union of operators << and is, and >> and is, respectively. (Implemented from Saxon 13.)

  • An ordering is defined over all instances of xs:duration, not just the subtypes. (Implemented from Saxon 13.)

  • Atomic types are categorized into type families to make it clear which values are comparable: atomic items belonging to types in the same family are mutually comparable, items belonging to different type families are not. For more information, see Types.