XQuery Reference

     Previous  Next    Open TOC in new window    View as PDF - New Window  Get Adobe Reader - New Window
Content starts here

XQuery String Functions Reference

This chapter provides descriptions of the XQuery string functions available in the mapper functionality of WebLogic Workshop. You use the mapper functionality to generate queries and add invocations to these XQuery functions in these queries.

In addition to the XQuery functions and operators available in the mapper functionality, a larger set functions and operators is provided. You can manually add invocations to these functions and operators to queries in the Source View of the mapper functionality. For a list of these additional functions and operators, see the XQuery 1.0 and XPath 2.0 Functions and Operators - W3C Working Draft 16 August 2002 available from the W3C Web site at the following URL:

http://www.w3.org/TR/2002/WD-xquery-operators-20020816

This section lists the type conversion functions available from the mapper functionality:

 


xf:concat

Concatenates the string values of the passed in arguments.

Signatures

xf:concat(xs: string $string-var1, xs: string $string-var2, ... ) —> xs: string

Table 3-1 Arguments
Data Type
Argument
Description
$string-var1
Represents the first string to concatenate together.
$string-var2
Represents the second string to concatenate together.
. . .
 
Represents more strings to concatenate together.

Returns

Returns a string made up of arguments to this function concatenated together.

If the value of any of the string arguments is the empty sequence, the argument is treated as a zero-length string ("").

Table 3-2 Examples
This Query . . .
Generates This Result . . .
<r>{xf:concat("str1", "str2")}</r>
<r>str1str2</r>
<r>{xf:concat('str1', 'str2')}</r>
<r>str1str2</r>
<r>{xf:concat("str1")}</r>
<r>str1</r>
<r>{xf:concat(())}</r>
<r></r>
<r>{xf:concat("str1", "str2", "str3", "str4", "str5", "str6")}</r>
<r>str1str2str3str4str5str6</r>

Related Topics

W3C concat function description.

 


bea-xf: trim-left

Removes the leading white space from $string-var.

If the value of $string-var is the empty sequence, the following error is displayed in the mapper:

Error occurred while executing XQuery: Error loading the XQuery or XSLT for this method: Type error in function trim-left invocation: expected type [string@http://www.w3.org/2001/XMLSchema], given type empty

The empty sequence is a sequence containing zero items (), which is similar to null in SQL.

Signatures

bea-xf: trim-left(xs: string $string-var) —> xs: string

Table 3-3 Arguments
Data Type
Argument
Description
$string-var
Represents the string to trim.

Returns

Returns $string-var after the removal of the leading white space.

XQuery Compliance

Not a standard W3C XQuery function.

Examples
Remove Leading Spaces

Invoking trim-left(" abc ") returns the string "abc " as shown in the following example query:

<result>{bea-xf:trim-left(" abc ")}</result>

The preceding query, generates the following XML result:

<result>abc </result>

Error—Null

Invoking trim-left(()) outputs an error. The string: () is the empty sequence (similar to a SQL null) which is a sequence containing zero items.

For example, the following example query:

<result>{bea-xf:trim-left(())}</result>

Outputs the following error:

Error occurred while executing XQuery: Error loading the XQuery or XSLT for this method: Type error in function trim-left invocation: expected type [string@http://www.w3.org/2001/XMLSchema], given type empty

 


bea-xf: trim-right

Removes the trailing white space from $string-var.

If the value of $string-var is the empty sequence, the following error is displayed in the mapper:

Error occurred while executing XQuery: Error loading the XQuery or XSLT for this method: Type error in function trim-right invocation: expected type [string@http://www.w3.org/2001/XMLSchema], given type empty

The empty sequence is a sequence containing zero items (), which is similar to null in SQL.

Signatures

bea-xf: trim-right(xs: string $string-var) —>xs:string

Table 3-4 Arguments
Data Type
Argument
Description
$string-var
Represents the string to trim.

Returns

Returns $string-var after the removal of the trailing white space.

Examples
Remove Trailing Spaces

Invoking trim-right(" abc ") returns the string " abc" as shown in the following example query:

<result>{bea-xf:trim-right(" abc ")}</result>

The preceding query, generates the following XML result:

<result> abc</result>

Error—Null

Invoking trim-right(()) outputs an error. The string: () is the empty sequence (similar to a SQL null) which is a sequence containing zero items.

For example, the following example query:

<result>{bea-xf:trim-right(())}</result>

Outputs the following error:

Error occurred while executing XQuery: Error loading the XQuery or XSLT for this method: Type error in function trim-right invocation: expected type [string@http://www.w3.org/2001/XMLSchema], given type empty

XQuery Compliance

Not a standard W3C XQuery function.

 


bea-xf: trim

Removes the leading and trailing white space from $string-var.

If the value of $string-var is the empty sequence, the following error is displayed in the mapper:

Error occurred while executing XQuery: Error loading the XQuery or XSLT for this method: Type error in function trim invocation: expected type [string@http://www.w3.org/2001/XMLSchema], given type empty

The empty sequence is a sequence containing zero items (), which is similar to null in SQL.

Signatures

bea-xf:trim(xs: string $string-var) —> xs: string

Table 3-5 Arguments
Data Type
Argument
Description
$string-var
Represents the string to trim.

Returns

Returns $string-var after the removal of the leading and trailing white space.

Examples
Remove Leading and Trailing Spaces

Invoking trim(" abc ") returns the string "abc" as shown in the following example query:

<result>{bea-xf:trim(" abc ")}</result>

The preceding query, generates the following XML result:

<result>abc</result>

Error—Null

Invoking trim(()) outputs an error. The string: () is the empty sequence (similar to a SQL null) which is a sequence containing zero items.

For example, the following example query:

<result>{bea-xf:trim(())}</result>

Outputs the following error:

Error occurred while executing XQuery: Error loading the XQuery or XSLT for this method: Type error in function trim invocation: expected type [string@http://www.w3.org/2001/XMLSchema], given type empty

XQuery Compliance

Not a standard W3C XQuery function.

 


xs: normalizedString

Converts $string-var (a string) to the normalizedString data type. As part of the conversion, all occurrences of tabs (#x9), line feeds (#xA) and carriage returns (#xD) are replaced with spaces (#x20).

Signatures

xs:normalizedString(xs: string $string-var) —> xs: normalizedString

Table 3-6 Arguments
Data Type
Argument
Description
$string-var
Represents the string for conversion.

Returns

Returns $string-var after conversion to the normalizedString data type.

Examples
Remove Tabs

As part of the conversion to the normalizedString data type, tabs are replaced by spaces as shown in the following example query:

<result>{xf:normalizedString( "tab1 tab2 tab3 tab4")}</result>

The preceding query, generates the following XML result:

<result> tab1 tab2 tab3 tab4</result>

Remove Carriage Returns

As part of the conversion to the normalizedString data type, carriage returns are replaced by spaces as shown in the following example query:

<result>{xf:normalizedString("

CR1

CR2

")}</result>

The preceding query, generates the following XML result:

<result> CR1 CR2 </result>

Related Topics

W3C normalizedString data type description.

 


xs: token

Converts $string-var (a string) to a token data type.

As part of the conversion, the following steps occur:

All occurrences of tabs (#x9), line feeds (#xA) and carriage returns (#xD) are replaced with spaces (#x20).

Contiguous sequences of spaces (#x20) are collapsed to a single space (#x20)

Leading and trailing spaces (#x20) are removed.

Signatures

xs:token(xs: string $string-var) —> xs: token

Table 3-7 Arguments
Data Type
Argument
Description
$string-var
Represents the string for conversion.

Returns

Returns $string-var after conversion to the token data type.

Examples
Remove Tabs

As part of the conversion to the token data type, tabs are replaced by spaces and then all leading and trailing spaces are removed as shown in the following example query:

<result>{xf:token( "tab1 tab2 tab3 tab4")}</result>

The preceding query, generates the following XML result:

<result>tab1 tab2 tab3 tab4</result>

Note: The tab before the string tab1 becomes a space and then is removed. (All trailing and leading spaces are removed as part of the conversion.)
Remove Carriage Returns

As part of the conversion to the token data type, carriage returns are replaced by spaces and then all trailing and leading spaces are removed, as shown in the following example query:

<result>{xf:token("

CR1

CR2

")}</result>

The preceding query, generates the following XML result:

<result>CR1 CR2</result>

Note: The carriage returns before the string CR1 and after CR2, become spaces and then are removed. (All trailing and leading spaces are removed as part of the conversion.)
Collapse Spaces

As part of the conversion to the token data type, contiguous sequences of spaces (#x20) are collapsed to a single space (#x20) and leading and trailing spaces (#x20) are removed, as shown in the following example query:

<result>{xf:token(" x y z ")}</result>

The preceding query, generates the following XML result:

<result>x y z</result>

Related Topics

W3C token data type description.

 


xf: compare

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

Signatures

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

Table 3-8 Arguments
Data Type
Argument
Description
$string-var1
Represents the first comparison 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.

 


xf: starts-with

Determines if the $string-var1 starts with string specified in $string-var2.

Signatures

xf:starts-with(xs: string? $string-var1, xs: string? $string-var2) —> xs: boolean?

Table 3-9 Arguments
Data Type
Argument
Description
$string-var1
Represents the string to compare against.
$string-var2
Compare this string against $string-var1 to see if $string-var1 starts with this string.

Returns

Returns the boolean value of true, if $string-var1 starts with a string that is equal to $string-var2.

Returns the boolean value of false, if $string-var1 does not starts with a string that is equal to $string-var2.

Returns the boolean value true, if $string-var2 is a zero-length string ("").

Returns the boolean value false, if $string-var1 is a zero-length string ("") and $string-var2 is not a zero-length string.

If the value of $string-var1 or $string-var2 is the empty sequence, the empty sequence is returned. The empty sequence is a sequence containing zero items (), which is similar to null in SQL.

Table 3-10 Examples
This Query . . .
Generates This Result . . .
<r>{xf:starts-with("honeymoon", "honey")}</r>
<r>true</r>
<r>{xf:starts-with("honeymoon", "moon")}</r>
<r>false</r>
<r>{xf:starts-with("honeymoon", "hat")}</r>
<r>false</r>
<r>{xf:starts-with("honeymoon", "")}</r>
<r>true</r>
<r>{xf:starts-with("", "moon")}</r>
<r>false</r>
<r>{xf:starts-with("moon", ())}</r>
<r/>

Related Topics

W3C starts-with function description.

 


xf: ends-with

Determines if the $string-var1 ends with string specified in $string-var2.

Signatures

xf: ends-with(xs: string?$string-var1,xs: string? $string-var2) —> xs: boolean?

Table 3-11 Arguments
Data Type
Argument
Description
$string-var1
Represents the string to compare against.
$string-var2
Compare this string against $string-var1 to see if $string-var1 ends in this string.

Returns

Returns the boolean value of true, if $string-var1 ends with a string that is equal to $string-var2.

Returns the boolean value of false, if $string-var1 does not end with a string that is equal to $string-var2.

Returns the boolean value true, if $string-var2 is a zero-length string ("").

Returns the boolean value false, if $string-var1 is a zero-length string ("") and $string-var2 is not a zero-length string.

If the value of $string-var1 or $string-var2 is the empty sequence, the empty sequence is returned. The empty sequence is a sequence containing zero items (), which is similar to null in SQL.

Table 3-12 Examples
This Query . . .
Generates This Result . . .
<r>{xf:ends-with("honeymoon", "moon")}</r>
<r>true</r>
<r>{xf:ends-with("honeymoon", "honey")}</r>
<r>false</r>
<r>{xf:ends-with("honeymoon", "hat")}</r>
<r>false</r>
<r>{xf:ends-with("honeymoon", "")}</r>
<r>true</r>
<r>{xf:ends-with("", "moon")}</r>
<r>false</r>
<r>{xf:ends-with("moon", ())}</r>
<r/>

Related Topics

W3C ends-with function description.

 


xf: contains

Determines if $string-var1 contains the string specified in $string-var2.

If the value of $string-var1 or $string-var2 is an empty sequence, the empty sequence is returned. The empty sequence is a sequence containing zero items (), which is similar to null in SQL.

Signatures

xf:contains(xs: string?$string-var1, xs: string?$string-var2) —>xs: boolean?

Table 3-13 Arguments
Data Type
Argument
Description
$string-var1
Represents the string to compare against.
$string-var2
Compare this string against $string-var1 to see if this string is contained anywhere in $string-var1.

Returns

Returns the boolean value of true, if $string-var1 contains $string-var2.

Returns the boolean value of false, if $string-var1 does not contain $string-var2.

Returns the boolean value true, if $string-var2 is a zero-length string ("").

Returns the boolean value false, if $string-var1 is a zero-length string ("") and $string-var2 is not a zero-length string.

Table 3-14 Examples
This Query . . .
Generates This Result . . .
<r>{xf:contains("supercalifragilistic", "fragil")}</r>
<r>true</r>
<r>{xf:contains("supercalifragilistic", "honey")}</r>
<r>false</r>
<r>{xf:contains("supercalifragilistic", "")}</r>
<r>true</r>
<r>{xf:contains("", "honey")}</r>
<r>false</r>
<r>{xf:contains("honey", ())}</r>
<r/>

Related Topics

W3C contains function description.

 


xf: substring

Get a substring of $string-var at a particular index location.

If a positive integer is not passed into $decimal-var or $optional-decimal-var, the TransformException exception is raised with the RT_ILLEGAL_INDEX fault code. In the mapper the following error message is displayed:

Error occurred while executing XQuery: Index "-1" out of bounds (0, 5)

If the integer passed into $decimal-var is greater then the length of the $string-var, the TransformException exception is raised with the RT_ILLEGAL_INDEX fault code. In the mapper the following error message is displayed:

Error occurred while executing XQuery: Index "6" out of bounds (0, 5)

Where X is the out of bounds index, Y is the starting index, and Z is the ending index, for example Index "6" out of bounds (0, 5).

To learn more about using fault codes, see Getting the TransformException Fault Code Programmatically

Signatures

xf:substring(xs: string? $string-var, xs: decimal xs: $decimal-var) —> xs: string?

xf:substring(xs: string?$string-var, xs: decimal?$decimal-var,xs: decimal ?$decimal-var) —> xs: string?

Table 3-15 Arguments 
Data Type
Argument
Description
$string-var
Represents the source string.
$decimal-var
Represents the starting location to start extracting the substring to return.

Note: Use 1 to specify the first character of the string and not 0.

$optional-decimal-var
Optional—Represents the length of the extracted substring.

Returns
substring($string-var, $decimal-var)

Returns the part of the $string-var source string from the starting location specified by $decimal-var.

If the value of any of the two arguments is an empty sequence, the empty sequence is returned. The empty sequence is a sequence containing zero items (), which is similar to null in SQL.

substring($string-var, $decimal-var, $optional-decimal-var)

Returns the part of the $string-var source string from the starting location specified by $decimal-var and continuing for the number of characters specified by $optional-decimal-var.

If the value of any of the three arguments is an empty sequence, the empty sequence is returned. The empty sequence is a sequence containing zero items (), which is similar to null in SQL.

Examples
Specify Just the Starting Position

Invoking substring("supercalifragilistic", 15) returns the string: listic, as shown in the following example query:

<result>{xf:substring("supercalifragilistic", 15)}</result>

The preceding query generates the following result:

<result>listic</result>

Specify the Starting Position and Length

Invoking substring("supercalifragilistic", 1, 5) returns the string: super, as shown in the following example query:

<result>{xf:substring("supercalifragilistic", 1, 5)}</result>

The preceding query generates the following result:

<result>super</result>

Note: To specify the first character in a string, use 1 and not 0.
From the Middle of the String

Invoking substring("supercalifragilistic", 6, 4) returns the string: cali, as shown in the following example query:

<result>{xf:substring("supercalifragilistic", 6, 4)}</result>

The preceding query generates the following result:

<result>cali</result>

Pass in Null

Invoking substring((), 1) returns the null string as shown in the following example query:

<result>{xf:substring((), 1)}</result>

Note: The string: () is the empty sequence (similar to a SQL null) which is a sequence containing zero items.

The preceding query generates the following result:

<result/>

Error—Out of Bounds

Invoking substring("super", 6) outputs an error because the index specified (6) is longer than the string: super.

For example, the following example query:

<result>{xf:substring("super", 6)}</result>

Produces the following error:

Error occurred while executing XQuery: Index "6" out of bounds (0, 5)

Note: Indexing starts with the number 1 and not 0, so the index 6 is beyond the last character in the string: super. (The character r in the string: super is at index 5.)
Related Topics

W3C substring function description.

 


xf: string-length

Counts the length of $string-var.

If the value of $string-var is the empty sequence, the empty sequence is returned. The empty sequence is a sequence containing zero items (), which is similar to null in SQL.

Signatures

xf:string-length(xf: string?$string-var) —> xf: integer?

Table 3-16 Arguments
Data Type
Argument
Description
xs:string?
$string-var
Represents the string to count.

Returns

Returns an integer equal to the length of the $string-var.

Examples
Simple

Invoking string-length("moo cow") returns the integer 7, as shown in the following example query:

<result>{xf:string-length("moo cow")}</result>

The preceding query generates the following result:

<result>7</result>

Pass in Null

Invoking string-length(()) returns the null string as shown in the following example query:

<result>{xf:string-length(())}</result>

Note: The string:() is the empty sequence (similar to a SQL null) which is a sequence containing zero items.

The preceding query generates the following result:

<result/>

Related Topics

W3C string-length function description.

 


xf: substring-before

Finds the substring that precedes $string-var2 in $string-var1.

Signatures

xf:substring-before(xs: string ? $string-var1, xs:string? $string-var2) —> xs:string?

Table 3-17 Arguments
Data Type
Argument
Description
xs:string?
$string-var1
Represents the source string.
xs:string?
$string-var2
Represents the comparison string.

Returns

Returns the part of the $string-var1 source string that precedes $string-var2.

Returns the value of $string-var1, if $string-var2 is a zero-length string ("").

Returns a zero-length string (""), if $string-var1 does not contain $string-var2.

If the value of $string-var1 or $string-var2 is an empty sequence, the empty sequence is returned. The empty sequence is a sequence containing zero items (), which is similar to null in SQL.

Table 3-18 Examples
This Query . . .
Generates This Result . . .
<r>{xf:substring-before("super", "p")}</r>
<r>su</r>
<r>{xf:substring-before("super", "")}</r>
<r>super</r>
<r>{xf:substring-before("super", "z")}</r>
<r/>
<r>{xf:substring-before("super", ())}</r>
<r/>

Related Topics

W3C substring-before function description.

 


xf: substring-after

Finds the substring that follows $string-var2 in $string-var1.

Signatures

xf:substring-after(xs: string? $string-var1, xs:string?$string-var2)—> xs:string?

Table 3-19 Arguments
Data Type
Argument
Description
xs:string?
$string-var1
Represents the source string.
xs:string?
$string-var2
Represents the comparison string.

Returns

Returns the part of the $string-var1 source string that follows $string-var2.

Returns the value of $string-var1, if $string-var2 is a zero-length string ("").

Returns a zero-length string (""), if $string-var1 does not contain $string-var2.

If the value of $string-var1 or $string-var2 is the empty sequence, the empty sequence is returned. The empty sequence is a sequence containing zero items (), which is similar to null in SQL.

Table 3-20 Examples
This Query . . .
Generates This Result . . .
<r>{xf:substring-after("super", "p")}</r>
<r>er</r>
<r>{xf:substring-after("super", "")}</r>
<r>super</r>
<r>{xf:substring-after("super", "z")}</r>
<r/>
<r>{xf:substring-after("super", ())}</r>
<r/>

Related Topics

W3C substring-after function description.

 


xf: normalize-space

Removes the leading and trailing white space and replaces the duplicate white space characters by a single space from $string-var.

As part of the removal process, the following steps occur:

  1. All occurrences of tabs (#x9), line feeds (#xA) and carriage returns (#xD) are replaced with spaces (#x20).
  2. Contiguous sequences of spaces (#x20) are collapsed to a single space (#x20)
  3. Leading and trailing spaces (#x20) are removed.

If the value of $string-var is the empty sequence, the empty sequence is returned. The empty sequence is a sequence containing zero items (), which is similar to null in SQL.

Signatures

xf:normalize-space(xs: string?$string-var) —> xs:string?

Table 3-21 Arguments
Data Type
Argument
Description
xs:string?
$string-var
Represents the string for conversion.

Returns

Returns the $string-var after it has gone through the white space removal process (described above).

Examples
Collapse Spaces

As part of the conversion process, contiguous sequences of spaces (#x20) are collapsed to a single space (#x20) and leading and trailing spaces (#x20) are removed, as shown in the following example query:

<result>{xf:normalize-space(" x y z ")}</result>

The preceding query, generates the following XML result:

<result>x y z</result>

Pass in Null

Invoking normalize-space(()) returns the null string as shown in the following example query:

<result>{xf:normalize-space(())}</result>

Note: The string: () is the empty sequence (similar to a SQL null) which is a sequence containing zero items.

The preceding query generates the following result:

<result/>

Related Topics

W3C normalize-space function description.

 


xf: upper-case

Converts all the lowercase characters of $string-var to their uppercase form.

If the value of $string-var is the empty sequence, the empty sequence is returned. The empty sequence is a sequence containing zero items (), which is similar to null in SQL.

Signatures

xf:upper-case(xs: string? $string-var) —> xs:string?

Table 3-22 Arguments
Data Type
Argument
Description
xs:string?
$string-var
Represents the string to convert.

Returns

Returns the $string-var source string converted to uppercase characters.

Examples

Simple

Invoking upper-case("cat") returns the string CAT as shown in the following example query:

<result>{xf:upper-case("cat")}</result>

The preceding query generates the following result:

<result>CAT</result>

Pass in Null

Invoking upper-case(()) returns the null string as shown in the following example query:

<result>{xf:upper-case(())}</result>

Note: The string:() is the empty sequence (similar to a SQL null) which is a sequence containing zero items.

The preceding query generates the following result:

<result/>

Related Topics

W3C upper-case function description.

 


xf: lower-case

Converts all the lowercase characters of $string-var (a string) to their uppercase characters.

If the value of $string-var is the empty sequence, the empty sequence is returned. The empty sequence is a sequence containing zero items (), which is similar to null in SQL.

Signatures

xf:lower-case(xs: string? $string-var) —>xs:string?

Table 3-23 Arguments
Data Type
Argument
Description
xs:string?
$string-var
Represents the string to convert.

Returns

Returns the $string-var source string converted to lowercase characters.

Examples
Simple

Invoking lower-case("CAT") returns the string cat as shown in the following example query:

<result>{xf:lower-case("CAT")}</result>

The preceding query generates the following result:

<result>cat</result>

Pass in Null

Invoking lower-case(()) returns the null string as shown in the following example query:

<result>{xf:lower-case(())}</result>

Note: The string: () is the empty sequence (similar to a SQL null) which is a sequence containing zero items.

The preceding query generates the following result:

<result/>

Related Topics

W3C lower-case function description.

 


xf: translate

Replaces all occurrences of $string-var2 with $string-var3 in $string-var1.

If the value of $string-var1, $string-var2, or $string-var3 is the empty sequence, the empty sequence is returned. The empty sequence is a sequence containing zero items (), which is similar to null in SQL.

Signatures

xf:translate(xs: string? $string-var1, xs:string?$string-var2, xs:string?$string-var3) —> xs:string

Table 3-24 Arguments
Data Type
Argument
Description
xs:string?
$string-var1
Represents the source string.
xs:string?
$string-var2
Represents the search string.
xs:string?
$string-var3
Represents the replacement string.

Returns

Returns the value of $string-var1 after all occurrences of the $string-var2 in $string-var1 have been replaced with $string-var3. If the length of $string-var2 (the search string) is less than the length of $string-var3 (replacement string), then only N characters are substituted, where N is length of $string-var2. (See the third example below.)

Returns the value of $string-var1, if $string-var2 is a zero-length string ("").

Examples
Simple

Invoking translate("fghXfgh", "fgh", "yz") returns the string xyXyz as shown in the following example query:

<result>{xf:translate("fghXfgh", "fgh", "yz")}</result>

The preceding query generates the following result:

<result>yzXyz</result>

Replacement String Longer Than Source String

Invoking translate("abcdabc", "ab", "ABC") returns the string ABcdABc, as shown in the following example query:

<result>{xf:translate("abcdabc", "ab", "ABC")}</result>

The preceding query generates the following result:

<result>ABcdABc</result>

Note: Only the first two characters (AB) of the replacement string ABC are substituted because the length of ab (the search string) is less than the length of ABC (the replacement string). When the length of the search string is less than the length of the replacement string, the length of the search string determines the number characters substituted.
Replacement String Is Empty

Invoking translate("abcdabc", "abc", "") returns the string d because the replacement string is a zero-length string, as shown in the following example query:

<result>{xf:translate("abcdabc", "abc", "")}</result>

The preceding query generates the following result:

<result>d</result>

Search String Is Empty

Invoking translate("abcdabc", "", "AB") returns the string abcdabc because the search string is a zero-length string, as shown in the following example query:

<result>{xf:translate("abcdabc", "", "AB")}</result>

The preceding query generates the following result:

<result>abcdabc</result>

Pass in Null

Invoking translate((), "ab", "ABC") returns the null string as shown in the following example query:

<result>{xf:translate((), "ab", "ABC")}</result>

Note: The string: () is the empty sequence (similar to a SQL null) which is a sequence containing zero items.

The preceding query generates the following result:

<result/>

Related Topics

W3C translate function description.

 


xf: string-pad

Returns a string of made up of $decimal-var copies of $string-var concatenated together.

Signatures

xf:string-pad(xs: string? $string-var, xs: decimal? $decimal-var) —> xs:string?

Table 3-25 Arguments
Data Type
Argument
Description
xs:string?
$string-var
Represents the string to replicate.
xs:decimal?
$decimal-var
Represents the number of times to replicate $string-var.

Returns

Returns a string of made up of $decimal-var copies of $string-var concatenated together.

Returns the value of $string-var1, if $string-var2 is a zero-length string ("").

Returns a zero-length string (""), if $decimal-var is equal to 0.

If the value of $string-var or $decimal-var is the empty sequence, the empty sequence is returned. The empty sequence is a sequence containing zero items (), which is similar to null in SQL.

Table 3-26 Examples
This Query . . .
Generates This Result . . .
<r>{xf:string-pad("cat", 2)}</r>
<r>catcat</r>
<r>{xf:string-pad("super", 0)}</r>
<r/>
<r>{xf:string-pad("super", ())}</r>
<r/>

Related Topics

W3C string-pad function description.

 


xf: matches

Compares $string-var1 against the regular expression in string-var2.

If any character besides m or i is specified in $string-var3 (the flags string), the TransformException exception is raised with the RT_REGEXP_FLAGS fault code. In the mapper, the following error is displayed:

Error occurred while executing XQuery: Invalid regular expression syntax (flags: "a")

If the value of $string-var1, $string-var2, or $string-var3 is the empty sequence, the empty sequence is returned. The empty sequence is a sequence containing zero items (), which is similar to null in SQL.

If $string-var2 (the regular expression string) has no anchors and is found anywhere in $string-var1 (the source string), the regular expression string is considered to match and the boolean true is returned. (To learn more, see the following String Matches Example.) However, if anchors (^ $) are used in $string-var2 (the regular expression string), the anchors must match the start/end of either the string (for string mode) or line (for multiline mode). (To learn more, see the following Beginning Anchor Matches and Beginning Anchor Does Not Match Examples.)

Signatures

xf:matches(xs: string? $string-var1, xs:string? $string-var2) —>xs: boolean?

xf:matches(xs:string? $string-var1, xs:string? $string-var2, xs:string? $string-var3) —>xs: boolean?

Table 3-27 Arguments
Data Type
Argument
Description
xs:string?
$string-var1
Represents the source string.
xs:string?
$string-var2
Represents the regular expression string. To learn more, see Regular Expressions.
xs:string?
$string-var3
Specifies flags that affect the comparison to the regular expression. (Optional)
   
m
If specified the match operates in multiline mode. Otherwise, the match operates in string mode.
   
i
If specified the match operates in case-insensitive mode. By default, the match operates in case-sensitive mode.

Returns

Returns the boolean true if $string-var1 matches the regular expression supplied in $string-var2.

Returns the boolean false if $string-var1 does not matches the regular expression suppled in $string-var2.

Examples
Regular Expression Matches

Invoking matches("abc", "[cxy]") returns the boolean true because the character c of the regular expression [cxy] is found in the source string abc, as shown in the following example query:

<result>{xf:matches("abc", "[cxy]")}</result>

The preceding query generates the following result:

<result>true</result>

Regular Expression Does Not Match

Invoking matches("abc", "[xy]") returns the boolean false because none of the characters in the regular expression [xy] are in the source string abc, as shown in the following example query:

<result>{xf:matches("abc", "[xy]")}</result>

The preceding query generates the following result:

<result>false</result>

String Matches

Invoking matches("uvwxyz", "xyz") returns the boolean true because the regular expression string xyz is found in the source string uvwxyz, as shown in the following example query:

<result>{xf:matches("uvwxyz", "xyz")}</result>

The preceding query generates the following result:

<result>true</result>

Beginning Anchor Matches

Invoking matches("uvwxyz", "^uv") returns the boolean true because the source string uvwxyz does start with the string uv, as shown in the following example query:

<result>{xf:matches("uvwxyz", "^uv")}</result>

The preceding query generates the following result:

<result>true</result>

Note: The regular expression ^uv specifies that source string must start with the string uv to be a successful match.
Beginning Anchor Does Not Match

Invoking matches("uvwxyz", "^yz") returns the boolean false because the source string uvwxyz does not start with the string yz, as shown in the following example query:

<result>{xf:matches("uvwxyz", "^yz")}</result>

The preceding query generates the following result:

<result>false</result>

Note: The regular expression ^yz specifies that source string must start with the string yz to be a successful match.
Ending Anchor Matches

Invoking matches("uvwxyz", "yz$") returns the boolean true because the source string uvwxyz does end with the string uv, as shown in the following example query:

<result>{xf:matches("uvwxyz", "yz$")}</result>

The preceding query generates the following result:

<result>true</result>

Note: The regular expression yz$ specifies that source string must end with the string yz to be a successful match.
Ending Anchor Does Not Match

Invoking matches("uvwxyz", "vw$") returns the boolean false because the source string uvwxyz does not end with the string yz, as shown in the following example query:

<result>{xf:matches("uvwxyz", "vw$")}</result>

The preceding query generates the following result:

<result>false</result>

Note: The regular expression yz$ specifies that source string must end with the string yz to be a successful match.
Case-Insensitive Mode

Invoking matches("aBc", "abc", "i") returns the boolean true because the source string aBc does contain the string abc, if you ignore the case of the strings, as shown in the following example query:

<result>{xf:matches("aBc", "abc", "i")}</result>

The preceding query generates the following result:

<result>true</result>

Pass in Null

Invoking matches("abc", ()) returns the null string as shown in the following example query:

<result>{xf:matches("abc", ())}</result>

Note: The string: () is the empty sequence (similar to a SQL null) which is a sequence containing zero items.

The preceding query generates the following result:

<result/>

Related Topics

W3C matches function description.

W3C Regular Expressions description.

 


xf: replace

Substitutes all occurrences of the regular expression specified by $string-var2 in $string-var1 with $string-var3.

If any character besides m or i is specified in $string-var4 (the flags string), the TransformException exception is raised with the RT_REGEXP_FLAGS fault code. In the mapper the following error message is displayed:

Error occurred while executing XQuery: Invalid regular expression syntax (flags: "a")

If the value of $string-var1, $string-var2, $string-var3, or $string-var4 is the empty sequence, the empty sequence is returned. The empty sequence is a sequence containing zero items (), which is similar to null in SQL.

Signatures

xf:replace(xs: string? $string-var1, xs:string?$string-var2 xs:string?$string-var3) —> xs:string

xfreplace(xs:string $string-var1, xs:string $string-var2, xs:string $string-var3, xs:string? $string-var4) —> xs:string

Table 3-28 Arguments
Data Type
Argument
Description
xs:string?
$string-var1
Represents the source string.
xs:string?
$string-var2
Represents the regular expression string. To learn more, see Regular Expressions.
xs:string?
$string-var3
Represents the replacement string.
xs:string?
$string-var4
Specifies flags that affect the comparison to the regular expression. (Optional)
   
m
If specified the match operates in multiline mode. By default, the match operates in string mode.
   
i
If specified the match operates in case-insensitive mode. By default, the match operates in case-sensitive mode.

Returns

Returns the string after substitution has occurred. (All occurrences of the regular expression specified by $string-var2 in $string-var1 are replaced with $string-var3.)

Examples
Simple

Invoking replace("xyzaxyz", "yz", "o") returns the string xoaxo, as shown in the following example query:

<result>{xf:replace("xyzaxyz", "yz", "o")}</result>

The preceding query generates the following result:

<result>xoaxo</result>

Greedy Qualifiers

Invoking replace("xyzaxyz", "x.*z", "o") returns the string o because the regular expression x.*z behaves as a greedy qualifier—the entire source string is read in before the first match is attempted and only if the first match attempt (with the entire source string) fails, does the matcher reduce the size of the source string by one character and attempts to match again. This process is repeated until there are no more characters in the source string. In this case, the regular expression x.*z matches the entire source string xyzaxyz, so the entire source string is replaced by the string o, shown in the following example query:

<result>{xf:replace("xyzaxyz", "x.*z", "o")}</result>

The preceding query generates the following result:

<result>o</result>

Reluctant Qualifiers

Invoking replace("xyzaxyz", "x.*?z", "o") returns the string oao because the regular expression x.*?z behaves as a reluctant qualifier—matching starts at the beginning of the input string, reluctantly reading in characters one at a time, until a match is found. Once a match is found, replacement occurs and the rest of the input string is searched for more matches. In this case, the regular expression x.?z finds two matches in the source string xyzaxyz, so the two xyz strings in the source string are replaced with the string o, shown in the following example query:

<result>{xf:replace("xyzaxyz", "x.*?z", "o")}</result>

The preceding query generates the following result:

<result>oao</result>

Replacement String Is Empty

Invoking replace("xyzaxyz", "x", "") returns the string yzayz because the replacement string is a zero-length string, as shown in the following example query:

<result>{xf:replace("xyzaxyz", "x", "")}</result>

The preceding query generates the following result:

<result>yzayz</result>

Case-Insensitive Mode

Invoking replace("Xax", "x", "o", "i") returns the string oao. The i flag in $string-var4 specifies to ignore the case during matching, so in this case two replacements occur (X and x), as shown in the following example query:

<result>{xf:replace("Xax", "x", "o", "i")}</result>

The preceding query generates the following result:

<result>oao</result>

Pass in Null

Invoking replace("xyz", "xyz",()) returns the null string as shown in the following example query:

<result>{xf:replace("xyz", "xyz",())}</result>

Note: The string: () is the empty sequence (similar to a SQL null) which is a sequence containing zero items.

The preceding query generates the following result:

<result/>

Related Topics

W3C replace function description.

W3C Regular Expressions description.

 


xf: tokenize

Breaks up $string-var1 into substrings based on the regular expression delimiter specified in $string-var2.

If the value of $string-var1, $string-var2, or $string-var3 is the empty sequence, the empty sequence is returned. The empty sequence is a sequence containing zero items (), which is similar to null in SQL.

If any character besides m or i is specified in $string-var3 (the flags string), the TransformException exception is raised with the RT_REGEXP_FLAGS fault code. In the mapper the following error message is displayed:

Error occurred while executing XQuery: Invalid regular expression syntax (flags: "a")

Signatures

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

xf:tokenize( xs:string? $string-var1, xs:string? $string-var2 xs:string? $string-var3) —> xs:string*

Table 3-29 Arguments
Data Type
Argument
Description
xs:string?
$string-var1
Represents the source string.
xs:string?
$string-var2
Represents the regular expression which determines how to break up the source string. To learn more, see Regular Expressions.
xs:string?
$string-var3
Specifies flags that affect how the regular expression is interpreted. (Optional)
   
m
If specified the match operates in multiline mode. By default, the match operates in string mode.
   
i
If specified the match operates in case-insensitive mode. By default, the match operates in case-sensitive mode

Returns

Returns the strings after break up of $string-var1 based on the pattern specified in $string-var2 has occurred.

Examples
White Space Delimited List

Invoking tokenize("Jane fell down the hill", "\s") returns the following sequence of strings: ("Jane", "fell", "down", "the", "hill"). The regular expression \s specifies that the delimiter is white space, so in this case the source string is broken up by white space as shown in the following example query:

<l>{

for $tok in xf:tokenize("Jane fell down the hill", "\s")

return <i>{ $tok }</i>

}</l>

The preceding query generates the following result:

<l>

<i>Jane</i>

<i>fell</i>

<i>down</i>

<i>the</i>

<i>hill</i>

</l>

Comma Delimited List

Invoking tokenize("3,20,,27,60", ",") returns the following strings: ("3", "20","","27","60"). In this case, the delimiter is a comma, so the source string is broken up by commas as shown in the following example query:

<l>{

for $tok in xf:tokenize("3,20,,27,60", ",")

return <i>{ $tok }</i>

}</l>

The preceding query generates the following result:

<l>

<i>3</i>

<i>20</i>

<i></i>

<i>27</i>

<i>60</i>

</l>

Comma and White Space Delimited List

Invoking tokenize("3, 4, 27,67", ",\s") returns the following strings: ("3", "4", "27,67"). The regular expression,\s specifies that the delimiter is a comma with white space, so in this case the source string is broken up by a comma with white space as shown in the following example query:

<l>{

for $tok in xf:tokenize("3, 4, 27,67", ",\s")

return <i>{ $tok }</i>

}</l>

The preceding query generates the following result:

<l>

<i>3</i>

<i>4</i>

<i>27,67</i>

</l>

Note: The numbers 27 and 67 are not broken up as tokens because there is no white space between the 27 and the 67 in the source string (just a comma).
Case-Insensitive Mode

Invoking tokenize("1a2A3a4A5", "a", "i") returns the returns the following strings: ("1","2","3","4","5"). The i flag in $string-var3 specifies to ignore the case of the characters during matching, so in this case the source string is broken up by both the capital A and the lowercase a characters, as shown in the following example query:

<l>{

for $tok in xf:tokenize("1a2A3a4A5", "a", "i")

return <i>{ $tok }</i>

}</l>

The preceding query generates the following result:

<l>

<i>1</i>

<i>2</i>

<i>3</i>

<i>4</i>

<i>5</i>

</l>

Related Topics

W3C tokenize function description.

W3C Regular Expressions description.


  Back to Top       Previous  Next