Create Initial-capital letter by using XSLT

By using below template you can get initial capital letter for multiple word.

<xsl:call-template name="ginitcap">
        <xsl:with-param name="text"> <xsl:value-of select="your value here"/> </xsl:with-param>
</xsl:call-template>


<!-- Customised initial-capital template -->
<xsl:template name="ginitcap">
      <xsl:param name="text"/>
      <xsl:choose>
        <xsl:when test="contains($text,' ')">
          <xsl:call-template name="ginitcapword">
            <xsl:with-param name="text" select="substring-before($text,' ')"/>
          </xsl:call-template>
          <xsl:text> </xsl:text>
          <xsl:call-template name="ginitcap">
            <xsl:with-param name="text" select="substring-after($text,' ')"/>
          </xsl:call-template>
        </xsl:when>
        <xsl:otherwise>
          <xsl:call-template name="ginitcapword">
            <xsl:with-param name="text" select="$text"/>
          </xsl:call-template>
        </xsl:otherwise>
      </xsl:choose>
 </xsl:template>
 
 <xsl:template name="ginitcapword">
      <xsl:param name="text"/>
      <xsl:value-of select="translate(substring($text,1,1),'abcdefghijklmnopqrstuvwxyz','ABCDEFGHIJKLMNOPQRSTUVWXYZ')" /><xsl:value-of select="translate(substring($text,2,string-length($text)-1),'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz')" />
  </xsl:template>

Input :    your value here
Output : Your Value Here

0 comments:

Post a Comment

 
java4practices © 2013 | Designed by Ganesh Rengarajan