compare
Compares two strings
Description
The fn:compare function returns one of the values:
-1 if $comparand1 is less than $comparand2
0 if $comparand1 is equal to $comparand2
1 if $comparand1 is greater than $comparand2
A comparand is greater than the other comparand if it starts with the other comparand and has additional characters. For example, abc is greater than ab.
Comparison operators (=, !=, <, <=, >, >=) can also be used to compare strings, and you may find the syntax more convenient. However, if you need to use a specific collation other than the default, you must use the fn:compare function.
Parameters |
Description |
---|---|
comparand1:string() |
the first string to compare |
comparand2:string() |
the second string to compare |
collation:string() |
the collation to use for sorting |
Examples
XPath |
Results |
---|---|