Name
starts-with()
Determines whether the first argument string begins with the second argument.
Syntax
[1.0] booleanstarts-with(string,string)[2.0] xs:booleanstarts-with(xs:string,xs:string)[2.0] xs:booleanstarts-with(xs:string,xs:string,$collation as xs:string)
Inputs
Two strings.
[2.0] In XSLT 2.0, there is an optional third argument—the name of a collation that specifies how strings are compared.
Output
Assuming both arguments are not zero-length strings, if the
first string begins with the second, starts-with() returns the boolean
value true; otherwise, it
returns false. If the second
string is a zero-length string, starts-with() returns true. If the first string
and the second string are both zero-length
strings, starts-with()
returns true. If the first string is a
zero-length string but the second string is not, starts-with() returns false.
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
We’ll use this sample XML document:
<?xml version="1.0"?>
<!-- favorites.xml -->
<list>
<title>A few of my favorite albums</title>
<listitem>A Love Supreme</listitem>
<listitem>Beat Crazy</listitem>
<listitem>Here Come the Warm Jets</listitem>
<listitem>Kind of Blue</listitem>
<listitem>London Calling</listitem>
<listitem>Remain in Light</listitem>
<listitem>The Joshua Tree</listitem>
<listitem>The Indestructible Beat of Soweto</listitem>
</list>This stylesheet outputs the ...
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