XSLT 1.0 How to make text data Title Case Hmmm….. Interesting…..

Here is the solution it is messy but works for XSLT 1.0

I am getting late so straight away going for quick example


<?xml version="1.0" encoding="utf-8" ?>
<?xml-stylesheet type="text/xsl" href="test.xslt" ?>
bhumip safi


<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >
<xsl:output method="xml" encoding="UTF-8" indent="yes"/>

<!--- Consider Below As Function -->
<xsl:template name="ConvertTitleCase">
<xsl:param name="temp" />
<xsl:call-template name="TitleCase">
<xsl:with-param name="text" select="translate(normalize-space($temp), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz')" />
<xsl:template name="TitleCase">
<xsl:param name="text" />
<xsl:param name="lastletter" select="' '"/>
<xsl:if test="$text">
<xsl:variable name="thisletter" select="substring($text,1,1)"/>
<xsl:when test="$lastletter=' ' or $lastletter='/' or $lastletter='-'">
<xsl:value-of select="translate($thisletter,'abcdefghijklmnopqrstuvwxyz','ABCDEFGHIJKLMNOPQRSTUVWXYZ')"/>
<xsl:value-of select="$thisletter"/>
<xsl:call-template name="TitleCase">
<xsl:with-param name="text" select="substring($text,2)"/>
<xsl:with-param name="lastletter" select="$thisletter"/>

<!--- Consider Below As Caller Of Function -->
<xsl:template match="/">
<xsl:apply-templates select="data" />
<xsl:template match="data">
<xsl:call-template name="ConvertTitleCase">
<xsl:with-param name="temp" select="input" />


How every need to code much compare to other languages but
Wallah — problem solved


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s