compare function
The fn:compare function compares two strings.
Syntax
- string-1 , string-2
- The xs:string values that are to be compared.
Returned value
- -1
- If string-1 is less than string-2.
- 0
- If string-1 is equal to string-2.
- 1
- If string-1 is greater than string-2.
string-1 and string-2 are equal if they have the same length, including a length of zero, and all corresponding characters are equal according to the default collation.
If string-1 and string-2 are not equal, their relationship (that is, which has the greater value) is determined by the comparison of the first pair of unequal characters from the left end of the strings. This comparison is made according to the default collation.
If string-1 is longer than string-2, and all characters of string-2 are equal to the leading characters of string-1, string-1 is greater than string-2.
If string-1 or string-2 is the empty sequence, the empty sequence is returned.
Example
The following function compares 'ABC' to 'ABD' using the default collation.
fn:compare('ABC', 'ABD')
'ABC' is less than 'ABD'. The returned value is -1.