Previous | Next | Indexes
adultinternetusers > Tutorials > XSLT 2.0 Tutorial > Functions operating on strings (3/15) >

Comparing starts and ends of strings

The functions starts-with() and ends-with() test whether the first argument starts or ends with the second one. The comparisons are case-sensitive.

XSLT

      <xsl:stylesheet
                  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                  version="2.0">
            <xsl:output  method="xml"
                        indent="yes"
                        omit-xml-declaration="yes"/>

            <xsl:template  match="/aaa">
                  <xxx>
                        <i>
                              <xsl:value-of  select="starts-with(bbb,'Hell')"/>
                        </i>
                        <ii>
                              <xsl:value-of  select="starts-with(bbb,'hell')"/>
                        </ii>
                  </xxx>
                  <yyy>
                        <i>
                              <xsl:value-of  select="ends-with(bbb,'!')"/>
                        </i>
                        <ii>
                              <xsl:value-of  select="ends-with(ddd,'.xml')"/>
                        </ii>
                  </yyy>
                  <zzz>
                        <i>
                              <xsl:value-of  select="starts-with(bbb,ccc)"/>
                        </i>
                        <ii>
                              <xsl:value-of  select="starts-with(ddd,lower-case(ccc))"/>
                        </ii>
                  </zzz>
            </xsl:template>

      </xsl:stylesheet>
XML

      <aaa>
            <bbb>Hello, world!</bbb>
            <ccc>Hello</ccc>
            <ddd>hello.xml</ddd>
      </aaa>
Output

      <xxx>
            <i>true</i>
            <ii>false</ii>
      </xxx>
      <yyy>
            <i>true</i>
            <ii>true</ii>
      </yyy>
      <zzz>
            <i>true</i>
            <ii>true</ii>
      </zzz>


Previous chapter: Arithmetics
Next chapter: Transforming strings with regular expressions
Previous page: Testing for a substring in a string with contains function
Next page: Comparisons of two strings with function compare

Kevin Carr in Stanton

Natural Skin Care and European Soaps
TickTalk 5
city of stanton
internetusers


You can also get Organic Skin Care products from Bliss Bath Body and you must check out their Natural Body Lotions and bath soaps

Now if you are looking for the best deals on surf clothing from Quiksilver and Roxy then you have to check these amazing deals here:

Hey, check out this Organic Skin Care European Soaps along with Natural Lavender Body Lotion and shea butter

and we can get surf t shirts surfing shirt and And you must check out this website swim suit swimming suit and swim trunks