Return substring of a string value.
The following construct(s) refer to this construct:
fn:substring(string $string, double $position) => string?
fn:substring(string $string, double $position, double $length) => string?
This function returns that part of $string
, which
begins at $position
and is the number of characters
indicated by length
. More precisely, the function
returns the characters in $string
, whose position
$p
satisfies:
fn:round($position) <= $p < fn:round($position) + fn:round($length)
The following rules hold:
If $length
is not specified or if
$length
is greater than the number of characters in the
value of $string
following
$position
, the substring includes characters to the end
of $string
.
If $position
is zero or negative, the substring
includes characters from the beginning of the
$string
.
It is an error if $string
is the empty
sequence.
$string |
string value |
---|---|
$position |
double value: the position at which the search takes place |
$length |
double value: the length of the substring |
Both queries below return " XML":
substring("Tamino XML Server", 7, 4) substring("Tamino XML Server", 6.5, 4.4)
Like the first query, the second one looks for four characters beginning at position 7.
Return the second half of the specified string:
let $text := "Tamino XML Server" return substring($text, string-length($text) div 2)