XPath/XQuery Functions: String

www.altova.com Expand/Collapse All Print this Topic Previous Page Up One Level Next page

Home >  Appendices > XSLT and XPath/XQuery Functions > Altova Extension Functions >

XPath/XQuery Functions: String

Altova's string extension functions can be used in XPath and XQuery expressions and provide additional functionality for the processing of data. The functions in this section can be used with Altova's XPath 3.0 and XQuery 3.0 engines. They are available in XPath/XQuery contexts.

 

Note about naming of functions and language applicability

Altova extension functions can be used in XPath/XQuery expressions. They provide additional functionality to the functionality that is available in the standard library of XPath, XQuery, and XSLT functions. Altova extension functions are in the Altova extension functions namespace, http://www.altova.com/xslt-extensions, and are indicated in this section with the prefix altova:, which is assumed to be bound to this namespace. Note that, in future versions of your product, support for a function might be discontinued or the behavior of individual functions might change. Consult the documentation of future releases for information about support for Altova extension functions in that release.

 

XPath functions (used in XPath expressions in XSLT):

XP1 XP2 XP3.1

XSLT functions (used in XPath expressions in XSLT):

Xslt1 XSLT2 XSLT3

XQuery functions (used in XQuery expressions in XQuery):

XQ1 XQ3.1

 

 

Click to expand/collapsecamel-case [altova:]

altova:camel-case(InputString as xs:string) as xs:string     XP3.1 XQ3.1

Returns the input string InputString in CamelCase. The string is analyzed using the regular expression '\s' (which is a shortcut for the whitespace character). The first non-whitespace character after a whitespace or sequence of consecutive whitespaces is capitalized. The first character in the output string is capitalized.

altova:camel-case("max") returns Max
altova:camel-case("max max") returns Max Max
altova:camel-case("file01.xml") returns File01.xml
altova:camel-case("file01.xml file02.xml") returns File01.xml File02.xml
altova:camel-case("file01.xml   file02.xml") returns File01.xml   File02.xml
altova:camel-case("file01.xml -file02.xml") returns File01.xml -file02.xml

 

altova:camel-case(InputString as xs:stringSplitChars as xs:stringIsRegex as xs:boolean) as xs:string     XP3.1 XQ3.1

Converts the input string InputString to camel case by using SplitChars to determine the character/s that trigger the next capitalization. SplitChars is used as a regular expression when IsRegex = true(), or as plain characters when IsRegex = false(). The first character in the output string is capitalized.

altova:camel-case("setname getname", "set|get", true()) returns setName getName
altova:camel-case("altova\documents\testcases", "\", false()) returns Altova\Documents\Testcases

 

 

Click to expand/collapsechar [altova:]

altova:char(Position as xs:integer) as xs:string     XP3.1 XQ3.1

Returns a string containing the character at the position specified by the Position argument, in the string obtained by converting the value of the context item to xs:string. The result string will be empty if no character exists at the index submitted by the Position argument.

If the context item is 1234ABCD:

 

altova:char(2) returns 2
altova:char(5) returns A
altova:char(9) returns the empty string.
altova:char(-2) returns the empty string.

 

altova:char(InputString as xs:stringPosition as xs:integer) as xs:string     XP3.1 XQ3.1

Returns a string containing the character at the position specified by the Position argument, in the string submitted as the InputString argument. The result string will be empty if no character exists at the index submitted by the Position argument.

altova:char("2014-01-15", 5) returns -
altova:char("USA", 1) returns U
altova:char("USA", 10) returns the empty string.
altova:char("USA", -2) returns the empty string.

 

 

Click to expand/collapsecreate-hash-from-string[altova:]

altova:create-hash-from-string(InputString as xs:string) as xs:string     XP2 XQ1 XP3.1 XQ3.1

altova:create-hash-from-string(InputString as xs:string, HashAlgo as xs:string) as xs:string     XP2 XQ1 XP3.1 XQ3.1

Generates a hash string from InputString by using the hashing algorithm specified by the HashAlgo argument. The following hashing algorithms may be specified (in upper or lower case): MD5, SHA-1, SHA-224, SHA-256, SHA-384, SHA-512. If the second argument is not specified (see the first signature above), then the SHA-256 hashing algorithm is used.

altova:create-hash-from-string('abc') returns a hash string generated by using the SHA-256 hashing algorithm.
altova:create-hash-from-string('abc', 'md5') returns a hash string generated by using the MD5 hashing algorithm.
altova:create-hash-from-string('abc', 'MD5') returns a hash string generated by using the MD5 hashing algorithm.

 

 

Click to expand/collapsefirst-chars [altova:]

altova:first-chars(X-Number as xs:integer) as xs:string     XP3.1 XQ3.1

Returns a string containing the first X-Number of characters of the string obtained by converting the value of the context item to xs:string.

If the context item is 1234ABCD:

 

altova:first-chars(2) returns 12
altova:first-chars(5) returns 1234A
altova:first-chars(9) returns 1234ABCD

 

altova:first-chars(InputString as xs:stringX-Number as xs:integer) as xs:string     XP3.1 XQ3.1

Returns a string containing the first X-Number of characters of the string submitted as the InputString argument.

altova:first-chars("2014-01-15", 5) returns 2014-
altova:first-chars("USA", 1) returns U

 

 

Click to expand/collapseformat-string [altova:]

altova:format-string(InputString as xs:stringFormatSequence as item()*) as xs:string     XP3.1 XQ3.1

The input string (first argument) contains positional parameters (%1, %2, etc). Each parameter is replaced by the string item that is located at the corresponding position in the format sequence (submitted as the second argument). So the first item in the format sequence replaces the positional parameter %1, the second item replaces %2, and so on. The function returns this formatted string that contains the replacements. If no string exists for a positional parameter, then the positional parameter itself is returned. This happens when the index of a positional parameter is greater than the number of items in the format sequence.

altova:format-string('Hello %1, %2, %3', ('Jane','John','Joe')) returns "Hello Jane, John, Joe"
altova:format-string('Hello %1, %2, %3', ('Jane','John','Joe''Tom')) returns "Hello Jane, John, Joe"
altova:format-string('Hello %1, %2, %4', ('Jane','John','Joe''Tom')) returns "Hello Jane, John, Tom"
altova:format-string('Hello %1, %2, %4', ('Jane','John','Joe')) returns "Hello Jane, John, %4"

 

 

Click to expand/collapselast-chars [altova:]

altova:last-chars(X-Number as xs:integer) as xs:string     XP3.1 XQ3.1

Returns a string containing the last X-Number of characters of the string obtained by converting the value of the context item to xs:string.

If the context item is 1234ABCD:

 

altova:last-chars(2) returns CD
altova:last-chars(5) returns 4ABCD
altova:last-chars(9) returns 1234ABCD

 

altova:last-chars(InputString as xs:stringX-Number as xs:integer) as xs:string     XP3.1 XQ3.1

Returns a string containing the last X-Number of characters of the string submitted as the InputString argument.

altova:last-chars("2014-01-15", 5) returns 01-15
altova:last-chars("USA", 10) returns USA

 

 

Click to expand/collapsepad-string-left [altova:]

altova:pad-string-left(StringToPad as xs:string, StringLength as xs:integer, PadCharacter as xs:string) as xs:string     XP3.1 XQ3.1

The PadCharacter argument is a single character. It is padded to the left of the string to increase the number of characters in StringToPad so that this number equals the integer value of the StringLength argument. The StringLength argument can have any integer value (positive or negative), but padding will occur only if the value of StringLength is greater than the number of characters in StringToPad. If StringToPad. has more characters than the value of StringLength, then StringToPad is left unchanged.

altova:pad-string-left('AP', 1, 'Z') returns 'AP'
altova:pad-string-left('AP', 2, 'Z') returns 'AP'
altova:pad-string-left('AP', 3, 'Z') returns 'ZAP'
altova:pad-string-left('AP', 4, 'Z') returns 'ZZAP'
altova:pad-string-left('AP', -3, 'Z') returns 'AP'
altova:pad-string-left('AP', 3, 'YZ') returns a pad-character-too-long error

 

 

Click to expand/collapsepad-string-right [altova:]

altova:pad-string-right(StringToPad as xs:string, StringLength as xs:integer, PadCharacter as xs:string) as xs:string     XP3.1 XQ3.1

The PadCharacter argument is a single character. It is padded to the right of the string to increase the number of characters in StringToPad so that this number equals the integer value of the StringLength argument. The StringLength argument can have any integer value (positive or negative), but padding will occur only if the value of StringLength is greater than the number of characters in StringToPad. If StringToPad has more characters than the value of StringLength, then StringToPad is left unchanged.

altova:pad-string-right('AP', 1, 'Z') returns 'AP'
altova:pad-string-right('AP', 2, 'Z') returns 'AP'
altova:pad-string-right('AP', 3, 'Z') returns 'APZ'
altova:pad-string-right('AP', 4, 'Z') returns 'APZZ'
altova:pad-string-right('AP', -3, 'Z') returns 'AP'
altova:pad-string-right('AP', 3, 'YZ') returns a pad-character-too-long error

 

 

Click to expand/collapserepeat-string [altova:]

altova:repeat-string(InputString as xs:string, Repeats as xs:integer) as xs:string     XP2 XQ1 XP3.1 XQ3.1

Generates a string that is composed of the first InputString argument repeated Repeats number of times.

altova:repeat-string("Altova #", 3) returns "Altova #Altova #Altova #"

 

 

Click to expand/collapsesubstring-after-last [altova:]

altova:substring-after-last(MainString as xs:string, CheckString as xs:string) as xs:string     XP3.1 XQ3.1

If CheckString is found in MainString, then the substring that occurs after CheckString in MainString is returned. If CheckString is not found in MainString, then the empty string is returned. If CheckString is an empty string, then MainString is returned in its entirety. If there is more than one occurrence of CheckString in MainString, then the substring after the last occurrence of CheckString is returned.

altova:substring-after-last('ABCDEFGH', 'B') returns 'CDEFGH'
altova:substring-after-last('ABCDEFGH', 'BC') returns 'DEFGH'
altova:substring-after-last('ABCDEFGH', 'BD') returns ''
altova:substring-after-last('ABCDEFGH', 'Z') returns ''
altova:substring-after-last('ABCDEFGH', '') returns 'ABCDEFGH'
altova:substring-after-last('ABCD-ABCD', 'B') returns 'CD'
altova:substring-after-last('ABCD-ABCD-ABCD', 'BCD') returns ''

 

 

Click to expand/collapsesubstring-before-last [altova:]

altova:substring-before-last(MainString as xs:string, CheckString as xs:string) as xs:string     XP3.1 XQ3.1

If CheckString is found in MainString, then the substring that occurs before CheckString in MainString is returned. If CheckString is not found in MainString, or if CheckString is an empty string, then the empty string is returned. If there is more than one occurrence of CheckString in MainString, then the substring before the last occurrence of CheckString is returned.

altova:substring-before-last('ABCDEFGH', 'B') returns 'A'
altova:substring-before-last('ABCDEFGH', 'BC') returns 'A'
altova:substring-before-last('ABCDEFGH', 'BD') returns ''
altova:substring-before-last('ABCDEFGH', 'Z') returns ''
altova:substring-before-last('ABCDEFGH', '') returns ''
altova:substring-before-last('ABCD-ABCD', 'B') returns 'ABCD-A'
altova:substring-before-last('ABCD-ABCD-ABCD', 'ABCD') returns 'ABCD-ABCD-'

 

 

Click to expand/collapsesubstring-pos [altova:]

altova:substring-pos(StringToCheck as xs:stringStringToFind as xs:string) as xs:integer     XP3.1 XQ3.1

Returns the character position of the first occurrence of StringToFind in the string StringToCheck. The character position is returned as an integer. The first character of StringToCheck has the position 1. If StringToFind does not occur within StringToCheck, the integer 0 is returned. To check for the second or a later occurrence of StringToCheck, use the next signature of this function.

altova:substring-pos('Altova', 'to') returns 3
altova:substring-pos('Altova', 'tov') returns 3
altova:substring-pos('Altova', 'tv') returns 0
altova:substring-pos('AltovaAltova', 'to') returns 3

 

altova:substring-pos(StringToCheck as xs:stringStringToFind as xs:stringInteger as xs:integer) as xs:integer     XP3.1 XQ3.1

Returns the character position of StringToFind in the string, StringToCheck. The search for StringToFind starts from the character position given by the Integer argument; the character substring before this position is not searched. The returned integer, however, is the position of the found string within the entire string, StringToCheck. This signature is useful for finding the second or a later position of a string that occurs multiple times with the StringToCheck. If StringToFind does not occur within StringToCheck, the integer 0 is returned.

altova:substring-pos('Altova', 'to', 1) returns 3
altova:substring-pos('Altova', 'to', 3) returns 3
altova:substring-pos('Altova', 'to', 4) returns 0
altova:substring-pos('Altova-Altova', 'to', 0) returns 3
altova:substring-pos('Altova-Altova', 'to', 4) returns 10

 

 

Click to expand/collapsetrim-string [altova:]

altova:trim-string(InputString as xs:string) as xs:string     XP3.1 XQ3.1

This function takes an xs:string argument, removes any leading and trailing whitespace, and returns a "trimmed" xs:string.

altova:trim-string("   Hello World   ")) returns "Hello World"
altova:trim-string("Hello World   ")) returns "Hello World"
altova:trim-string("   Hello World")) returns "Hello World"
altova:trim-string("Hello World")) returns "Hello World"
altova:trim-string("Hello   World")) returns "Hello   World"

 

 

Click to expand/collapsetrim-string-left [altova:]

altova:trim-string-left(InputString as xs:string) as xs:string     XP3.1 XQ3.1

This function takes an xs:string argument, removes any leading whitespace, and returns a left-trimmed xs:string.

altova:trim-string-left("   Hello World   ")) returns "Hello World   "
altova:trim-string-left("Hello World   ")) returns "Hello World   "
altova:trim-string-left("   Hello World")) returns "Hello World"
altova:trim-string-left("Hello World")) returns "Hello World"
altova:trim-string-left("Hello   World")) returns "Hello   World"

 

 

Click to expand/collapsetrim-string-right [altova:]

altova:trim-string-right(InputString as xs:string) as xs:string     XP3.1 XQ3.1

This function takes an xs:string argument, removes any trailing whitespace, and returns a right-trimmed xs:string.

altova:trim-string-right("   Hello World   ")) returns "   Hello World"
altova:trim-string-right("Hello World   ")) returns "Hello World"
altova:trim-string-right("   Hello World")) returns "   Hello World"
altova:trim-string-right("Hello World")) returns "Hello World"
altova:trim-string-right("Hello   World")) returns "Hello   World"

 

 

 


© 2019 Altova GmbH