XPath/XQuery compare function

Summary

Returns -1, 0, or 1, depending on whether $comparand1 collates before, equal to, or after $comparand2 according to the rules of a selected collation.

Signatures

fn:compare(
$comparand1 as xs:string?,
$comparand2 as xs:string?
) as xs:integer?
fn:compare(
$comparand1 as xs:string?,
$comparand2 as xs:string?,
$collation as xs:string
) as xs:integer?

Properties

The two-argument form of this function is deterministic, context-dependent, and focus-independent. It depends on collations.
The three-argument form of this function is deterministic, context-dependent, and focus-independent. It depends on collations static-base-uri.

Rules

Returns -1, 0, or 1, depending on whether the value of the $comparand1 is respectively less than, equal to, or greater than the value of $comparand2, according to the rules of the collation that is used.

The collation used by this function is determined according to the rules in .

If either $comparand1 or $comparand2 is the empty sequence, the function returns the empty sequence.

This function, called with the first signature, defines the semantics of the "eq", "ne", "gt", "lt", "le" and "ge" operators on xs:string values.

Examples

The expression fn:compare('abc', 'abc') returns 0.

The expression fn:compare('Strasse', 'Straße') returns 0.

The expression fn:compare('Strasse', 'Straße', 'http://www.w3.org/2013/collation/UCA?lang=de;strength=primary') returns 0.

The expression fn:compare('Strassen', 'Straße') returns 1.