Cover Image for XQuery String functions
124 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:

  1. fn:string():
  • Converts any data type to a string representation.
  1. fn:string-length($input-string):
  • Returns the length of the input string as an integer.
  1. 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).
  1. fn:concat($string1, $string2, …):
  • Concatenates two or more strings into a single string.
  1. fn:contains($input-string, $search-string):
  • Checks if the input string contains the search string and returns a boolean value.
  1. fn:starts-with($input-string, $prefix):
  • Checks if the input string starts with the specified prefix and returns a boolean value.
  1. fn:ends-with($input-string, $suffix):
  • Checks if the input string ends with the specified suffix and returns a boolean value.
  1. fn:upper-case($input-string):
  • Converts the input string to uppercase.
  1. fn:lower-case($input-string):
  • Converts the input string to lowercase.
  1. fn:translate($input-string, $mapString, $replaceString):
  • Replaces characters in the input string based on the mapping defined in the mapString and replaceString.
  1. fn:substring-before($input-string, $delimiter):
  • Extracts the substring before the first occurrence of the delimiter in the input string.
  1. fn:substring-after($input-string, $delimiter):
  • Extracts the substring after the first occurrence of the delimiter in the input string.
  1. fn:replace($input-string, $pattern, $replacement):
  • Replaces occurrences of the pattern in the input string with the replacement.
  1. fn:normalize-space($input-string):
  • Removes leading and trailing spaces from the input string and replaces consecutive internal spaces with a single space.
  1. fn:encode-for-uri($input-string):
  • Encodes the input string for use in a URI or URL.
  1. 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.

YOU MAY ALSO LIKE...

The Tech Thunder

The Tech Thunder

The Tech Thunder


COMMENTS