How to use starts-with operation in String Function Using XPath in Xml

In this article I will explain starts-with operation of string function.
  • 2361


starts-with operation/function is a part of string function in XPath. This function takes two string argument and check whether the first string argument starts with the second string argument or not. If the first string starts with the second string  then this function returns true otherwise return false.


boolean starts-with(string1,string2)

Hear starts-with is a function that takes two string argument to check whether the first string is starts with the second string or not if yes then return a Boolean value true otherwise return false.


The following example shows how we use the starts-with function,

Code for starts_with.xml

<?xml version="1.0" encoding="utf-8" ?>

<?xml-stylesheet type="text/xsl" href="starts.xslt"?>







    <Name>Megha garg</Name>













Code for starts.xslt


<?xml version="1.0" encoding="utf-8"?>

<xsl:stylesheet version="1.0" xmlns:xsl=""

    xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl">

  <xsl:output method="html" omit-xml-declaration="yes"/>

  <xsl:template match="/">






        <xsl:apply-templates select="//Student"/>




  <xsl:template match="Student">

    <xsl:if test="starts-with(Name, 'R')">



          <xsl:value-of select="Name"/>

        </B> lives in


          <xsl:value-of select="address"/>








When applied to the XML file (starts_with.xml), the XSLT style sheet above produces the following output:


Ask Your Question 

Got a programming related question? You may want to post your question here

Programming Answers here


More Articles

© 2020 DotNetHeaven. All rights reserved.