Share via

starts-with Function

Returns true if the first argument string starts with the second argument string; otherwise returns false.

boolean starts-with(string, string)


If an argument is not of type string, it is first converted to a string using the string() function and then the result of that conversion is evaluated.

Caution noteCaution

String conversions for node sets that are passed as arguments to this function may yield unexpected results. For more information, see string Function.

This function is case-sensitive.


The following example illustrates how to use the starts-with() function to query a collection of books whose title begins with a capital letter "W".

XML FILE (starts-with.xml)

<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" 

     <title>The Weather Pattern</title>
     <author>Weather Man</author>
     <title>Weaving Patterns</title>
     <title>Speech Pattern</title>
     <title>Writing Style</title>

XSLT FILE (starts-with.xsl)

<?xml version='1.0'?>
<xsl:stylesheet version="1.0"           


  <xsl:output method="html"   

  <xsl:template match="/">
       <xsl:apply-templates select="//book"/>

  <xsl:template match="book">
     <xsl:if test="starts-with(title, 'W')">
         <B><xsl:value-of select="title"/></B> by 
         <I><xsl:value-of select="author"/></I> costs
         <xsl:value-of select="price"/>.



This XSLT style sheet, when applied to the XML file (starts-with.xml) produces the following output:

Weaving Patterns by Weaver costs 150.00.

Writing Style by Writer costs 1500.00.

See Also


XML Data Types Reference