![]() ![]() ![]() ![]() ![]() ![]() |
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:
Concatenates the string values of the passed in arguments.
xf:concat
(xs:
string $string-var1
, xs:
string $string-var2, ...
) —> xs:
string
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 ("").
W3C concat function description.
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.
bea-xf: trim-left
(xs:
string $string-var
) —> xs:
string
Returns $string-var
after the removal of the leading white space.
Not a standard W3C XQuery function.
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:
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>
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
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.
bea-xf: trim-right(
xs:
string $string-var) —>xs:string
Returns $string-var
after the removal of the trailing white space.
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:
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>
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
Not a standard W3C XQuery function.
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.
bea-xf:trim
(xs:
string $string-var
) —> xs:
string
Returns $string-var
after the removal of the leading and trailing white space.
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:
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>
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
Not a standard W3C XQuery function.
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)
.
xs:normalizedString
(xs:
string $string-var
) —> xs:
normalizedString
Returns $string-var after conversion to the normalizedString data type.
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>
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("
The preceding query, generates the following XML result:
W3C normalizedString data type description.
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.
xs:token
(xs:
string $string-var
) —> xs:
token
Returns $string-var
after conversion to the
token data type.
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.) |
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:
The preceding query, generates the following XML 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.) |
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:
W3C token data type description.
Compares the value of $string-var1
to $string-var2
.
xf:compare
(xs:
string? $string-var1
, xs:
string?$string-var2
) —> xs:integer?
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
.
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:
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:
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:
W3C compare function description.
Determines if the $string-var1
starts with string specified in $string-var2
.
xf:starts-with
(xs:
string? $string-var1
, xs:
string? $string-var2
) —> xs:
boolean?
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.
W3C starts-with function description.
Determines if the $string-var1
ends with string specified in $string-var2
.
xf: ends-with
(xs:
string?$string-var1
,xs:
string? $string-var2
) —> xs:
boolean?
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.
W3C ends-with function description.
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.
xf:contains
(xs:
string?$string-var1
, xs:
string?$string-var2
) —>xs:
boolean?
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.
W3C contains function description.
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
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?
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.
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.
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:
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:
Note: | To specify the first character in a string, use 1 and not 0. |
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:
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:
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>
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.) |
W3C substring function description.
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.
xf:string-length
(xf:
string?$string-var
) —> xf: integer?
xs:string?
|
Returns an integer equal to the length of the $string-var.
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:
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:
W3C string-length function description.
Finds the substring that precedes $string-var2
in $string-var1.
xf:substring-before(xs:
string ? $string-var1, xs:string? $string-var2) —> xs:string?
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.
W3C substring-before function description.
Finds the substring that follows $string-var2
in $string-var1
.
xf:substring-after
(xs:
string? $string-var1, xs:string?$string-var2)—> xs:string?
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.
W3C substring-after function description.
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:
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.
xf:normalize-space(
xs:
string?$string-var) —> xs:string?
Returns the $string-var
after it has gone through the white space removal process (described above).
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:
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:
W3C normalize-space function description.
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.
xf:upper-case(
xs:
string? $string-var) —> xs:string?
Returns the $string-var
source string converted to uppercase characters.
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:
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:
W3C upper-case function description.
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.
xf:lower-case(
xs:
string? $string-var) —>xs:string?
Returns the $string-var
source string converted to lowercase characters.
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:
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:
W3C lower-case function description.
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.
xf:translate(
xs:
string? $string-var1
, xs:string?$string-var2, xs:string?$string-var3) —> xs:string
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 ("")
.
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:
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:
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. |
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:
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:
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:
W3C translate function description.
Returns a string of made up of $decimal-var
copies of $string-var
concatenated together.
xf:string-pad(
xs:
string? $string-var
, xs: decimal? $decimal-var) —> xs:string?
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.
W3C string-pad function description.
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.)
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?
Represents the regular expression string. To learn more, see
Regular Expressions.
|
|||
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.
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:
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:
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:
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:
Note: | The regular expression ^uv specifies that source string must start with the string uv to be a successful 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:
Note: | The regular expression ^yz specifies that source string must start with the string yz to be a successful match. |
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:
Note: | The regular expression yz$ specifies that source string must end with the string yz to be a successful 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:
Note: | The regular expression yz$ specifies that source string must end with the string yz to be a successful match. |
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:
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:
W3C matches function description.
W3C Regular Expressions description.
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.
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
Represents the regular expression string. To learn more, see
Regular Expressions.
|
|||
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.
)
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:
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:
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:
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:
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:
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:
W3C replace function description.
W3C Regular Expressions description.
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")
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*
Represents the regular expression which determines how to break up the source string. To learn more, see
Regular Expressions.
|
|||
Returns the strings after break up of $string-var1
based on the pattern specified in $string-var2
has occurred.
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:
for $tok in xf:tokenize("Jane fell down the hill", "\s")
The preceding query generates the following result:
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:
for $tok in xf:tokenize("3,20,,27,60", ",")
The preceding query generates the following result:
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:
for $tok in xf:tokenize("3, 4, 27,67", ",\s")
The preceding query generates the following result:
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). |
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:
for $tok in xf:tokenize("1a2A3a4A5", "a", "i")
The preceding query generates the following result:
W3C tokenize function description.
W3C Regular Expressions description.
![]() ![]() ![]() |