xpath2 | string functions

www.altova.com Print this Topic Previous Page Up One Level Next page

Home >  Functions > Function Library Reference >

xpath2 | string functions

The following XPath 2 string functions are available:

 

compare

The compare function takes two strings as arguments and compares them for equality and alphabetically. If String-1 is alphabetically less than String-2 (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 String-1 is greater than String-2 (for example, B and A), then the function returns +1.

 

A variant of this function allows you to choose what collation is to be used to compare the strings. When no collation is used, the default collation, which is the Unicode codepoint collation, is used. The Altova Engines support the Unicode codepoint collation only.

 

ends-with

The ends-with function tests whether String-1 ends with String-2. If yes, the function returns true, otherwise false.

 

A variant of this function allows you to choose what collation is to be used to compare the strings. When no collation is used, the default collation, which is the Unicode codepoint collation, is used. The Altova Engines support the Unicode codepoint collation only.

 

escape-uri

The escape-uri function takes a URI as input for the first string argument and applies the URI escaping conventions of RFC 2396 to the string. The second boolean argument (escape-reserved) should be set to true() if characters with a reserved meaning in URIs are to be escaped (for example "+" or "/").

 

For example:

 

escape-uri("My A+B.doc", true()) would give My%20A%2B.doc

escape-uri("My A+B.doc", false()) would give My%20A+B.doc

 

lower-case

The lower-case function takes a string as its argument and converts every upper-case character in the string to its corresponding lower-case character.

 

matches

The matches function tests whether a supplied string (the first argument) matches a regular expression (the second argument). The syntax of regular expressions must be that defined for the pattern facet of XML Schema. The function returns true if the string matches the regular expression, false otherwise.

 

The function takes an optional flags argument. Four flags are defined (i, m, s, x). Multiple flags can be used: for example, imx. If no flag is used, the default values of all four flags are used.

 

The meaning of the four flags are as follows:

 

i

Use case-insensitive mode. The default is case-sensitive.

m

Use multiline mode, in which the input string is considered to have multiple lines, each separated by a newline character (x0a). The meta characters ^ and $ indicate the beginning and end of each line. The default is string mode, in which the string starts and ends with the meta characters ^ and $.

s

Use dot-all mode. The default is not-dot-all mode, in which the meta character "." matches all characters except the newline character (x0a). In dot-all mode, the dot also matches the newline character.

x

Ignore whitespace. By default whitespace characters are not ignored.

 

normalize-unicode

The normalize-unicode function normalizes the input string (the first argument) according to the rules of the normalization form specified (the second argument). The normalization forms NFC, NFD, NFKC, and NFKD are supported.

 

replace

The replace function takes the string supplied in the first argument as input, looks for matches as specified in a regular expression (the second argument), and replaces the matches with the string in the third argument.

 

The rules for matching are as specified for the matches attribute above. The function also takes an optional flags argument. The flags are as described in the matches function above.

 

starts-with

The starts-with function tests whether String-1 starts with String-2. If yes, the function returns true, otherwise false.

 

A variant of this function allows you to choose what collation is to be used to compare the strings. When no collation is used, the default collation, which is the Unicode codepoint collation, is used. The Altova Engines support the Unicode codepoint collation only.

 

substring-after

The substring-after function returns that part of String-1 (the first argument) that occurs after the test string, String-2 (the second argument). An optional third argument specifies the collation to use for the string comparison. When no collation is used, the default collation, which is the Unicode codepoint collation, is used. The Altova Engines support the Unicode codepoint collation only.

 

substring-before

The substring-before function returns that part of String-1 (the first argument) that occurs before the test string, String-2 (the second argument). An optional third argument specifies the collation to use for the string comparison. When no collation is used, the default collation, which is the Unicode codepoint collation, is used. The Altova Engines support the Unicode codepoint collation only.

 

upper-case

The upper-case function takes a string as its argument and converts every lower-case character in the string to its corresponding upper-case character.


© 2019 Altova GmbH