Name
substring()
Returns a portion of a given string.
Syntax
[1.0] stringsubstring(
$sourceString as string
,$startingLoc as number
,$length as number?
)
[2.0] xs:stringsubstring(
$sourceString as xs:string?
,$startingLoc as xs:double
)
[2.0] xs:stringsubstring(
$sourceString as xs:string?
,$startingLoc as xs:double
,$length as xs:double
)
Inputs
The substring()
function takes a string and one or two numbers as arguments. The
string is the string from which the substring will be extracted.
The second argument is used as the starting position of the
returned substring, and the optional third argument specifies how
many characters are returned.
Output
With two arguments (a string and a starting position), the
substring()
function
returns all characters in the string whose position is greater
than or equal to the starting position. Be aware that
the first character in a string is at position 1, not
0.
With three arguments (a string, a starting position, and a
length), the substring()
function returns all characters in the string whose position is
greater than or equal to the starting position or whose position
is less than the starting position plus the
length.
Normally, the arguments to the substring()
function are integers,
although they may be floating-point numbers or more complicated
expressions. In the case of floating-point numbers, the number is
converted to an integer by the round()
function.
Defined in
[1.0] XPath section 4.2, “String Functions.”
[2.0] XQuery 1.0 and XPath 2.0 Functions ...
Get XSLT, 2nd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.