fn:compare
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, and 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 Choosing a collation.
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
. (Assuming the default collation includes provisions that equate
ss and the (German) character ß
(sharp-s). Otherwise, the returned value depends on the
semantics of the default collation.)
The expression fn:compare('Strasse', 'Straße',
'http://www.w3.org/2013/collation/UCA?lang=de;strength=primary')
returns 0
. (The specified collation equates
ss and the (German) character ß
(sharp-s).)
The expression fn:compare('Strassen', 'Straße')
returns 1
. (Assuming the default collation includes provisions that treat
differences between ss and the (German) character ß
(sharp-s) with less strength than the differences between the
base characters, such as the final n. ).