166 views
XQuery String functions
XQuery provides a variety of string functions that allow you to manipulate and work with strings in XML data. Here are some commonly used XQuery string functions:
- fn:string():
- Converts any data type to a string representation.
- fn:string-length($input-string):
- Returns the length of the input string as an integer.
- fn:substring($input-string, $start, $length):
- Extracts a substring from the input string, starting at the specified position (1-based) and of the specified length (optional).
- fn:concat($string1, $string2, …):
- Concatenates two or more strings into a single string.
- fn:contains($input-string, $search-string):
- Checks if the input string contains the search string and returns a boolean value.
- fn:starts-with($input-string, $prefix):
- Checks if the input string starts with the specified prefix and returns a boolean value.
- fn:ends-with($input-string, $suffix):
- Checks if the input string ends with the specified suffix and returns a boolean value.
- fn:upper-case($input-string):
- Converts the input string to uppercase.
- fn:lower-case($input-string):
- Converts the input string to lowercase.
- fn:translate($input-string, $mapString, $replaceString):
- Replaces characters in the input string based on the mapping defined in the
mapString
andreplaceString
.
- fn:substring-before($input-string, $delimiter):
- Extracts the substring before the first occurrence of the delimiter in the input string.
- fn:substring-after($input-string, $delimiter):
- Extracts the substring after the first occurrence of the delimiter in the input string.
- fn:replace($input-string, $pattern, $replacement):
- Replaces occurrences of the
pattern
in the input string with thereplacement
.
- fn:normalize-space($input-string):
- Removes leading and trailing spaces from the input string and replaces consecutive internal spaces with a single space.
- fn:encode-for-uri($input-string):
- Encodes the input string for use in a URI or URL.
- fn:decode-for-uri($input-string):
- Decodes a URI-encoded input string.
These string functions are valuable for performing various text-related operations on XML data, such as extracting substrings, converting case, searching for patterns, and more. By utilizing these functions, you can efficiently process and manipulate string data within XML documents in XQuery.