# xf:compare

Compares the value of $string-var1 to $string-var2.

### Signatures

xf:compare(xs:string? $string-var1, xs:string? $string-var2) —> xs:integer?

### Arguments

Data Type | Argument | Description
--- | --- | ---
xs:string | $string-var1 | Represents the first comparison string.
xs:string | $string-var2 | Represents the second comparison string.

### Returns

Returns -1, 0, or 1, depending on whether the value of $string-var1 is less than (-1), equal to (0), or greater than (1) the value of $string-var2.

### Examples

#### Less Than (-1)

Invoking compare('abc', 'abcde') returns an integer -1, because $string-var1 is less than $string-var2, as shown by the following example query:

    <result>{xf:compare('abc', 'abcde')}</result>

The preceding query, generates the following XML result:

    <result>-1</result>

#### Equal (0)

Invoking compare('abc', 'abc') returns an integer 0, because the two string are equal, as shown by the following example query:

    <result>{xf:compare('abc', 'abc')}</result>

The preceding query, generates the following XML result:

    <result>0</result>

#### Greater Than (+1)

Invoking compare('abcde', 'abc') returns an integer 1, because $string-var1 is greater than $string-var2, as shown by the following example query:

    <result>{xf:compare('abcde', 'abc')}</result>

The preceding query, generates the following XML result:

    <result>1</result>

Related Topics

W3C compare function description.