O'Reilly logo

XSLT, 2nd Edition by Doug Tidwell

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Name

substring()

Returns a portion of a given string.

Syntax

[1.0] string substring($sourceString as string, $startingLoc as number, 
                       $length as number?)
[2.0] xs:string substring($sourceString as xs:string?, 
                          $startingLoc as xs:double)
[2.0] xs:string substring($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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required