Altova MapForce 2025 Enterprise Edition

The compare function takes two strings as arguments and compares them for equality and alphabetically, using the collation supplied as argument. If string1 is alphabetically less than string2 (for example the two string are "A" and "B"),  then the function returns -1. If the two strings are equal (for example, "A" and "A"), the function returns 0. If string1 is greater than string2 (for example, "B" and "A"), then the function returns 1.

mf-func-xpath2-compare2

 

Languages

XQuery, XSLT 2.0, XSLT 3.0.

 

Parameters

Name

Type

Description

string1

xs:string

The first input string.

string2

xs:string

The second input string.

collation

xs:string

Specifies the collation to use for string comparison. This input may originate from the output of the default-collation function or it may be a collation such as http://www.w3.org/2005/xpath-functions/collation/html-ascii-case-insensitive.

 

Example

The following mapping compares the strings "A" and "a" using the case insensitive collation http://www.w3.org/2005/xpath-functions/collation/html-ascii-case-insensitive, which is supplied by a constant.

mf-func-xpath2-compare-example1

XSLT 2.0 Mapping

The result of the mapping above is 0, meaning that both strings are treated as equal. However, if you replace the collation with the one provided by the default-collation function, the collation changes to the default Unicode code point collation, and the mapping result becomes -1 ("A" is alphabetically less than "a").

mf-func-xpath2-compare-example2

© 2018-2024 Altova GmbH