Name
substring-before()
Given a data string and a search string, returns the
portion of the data string before the first occurrence of the
search string. If the search string is not found, the substring-before() function returns
a zero-length string.
Syntax
[1.0] stringsubstring-before(string,string)[2.0] xs:stringsubstring-before(xs:string?,xs:string?)[2.0] xs:stringsubstring-before(xs:string?,xs:string?,$collation as xs:string)
Inputs
Two strings. The first string is the string to be searched, and the second is the string to be searched for in the first string.
[2.0] In XSLT 2.0, there is an optional third argument: the name of a collation that specifies how strings are compared.
Output
The portion of the data string that occurs before the first
occurrence of the search string. If the search string does not
appear in the data string, the function returns an empty string.
If the second string is a zero-length string, substring-before() returns a
zero-length string. The function also returns a zero-length string
if the first string is shorter than the second string.
Defined in
[1.0] XPath section 4.2, “String Functions.”
[2.0] XQuery 1.0 and XPath 2.0 Functions and Operators section 7.5, “Functions Based on Substring Matching.”
Example
Here is a sample stylesheet that uses substring-before():
<?xml version="1.0"?>
<!-- substring-before1.xsl --> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="text"/> <xsl:template match="/"> <xsl:text>
A ...Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access