Skip to content

Instantly share code, notes, and snippets.

@jdsimcoe
Created December 8, 2012 16:01
Show Gist options
  • Select an option

  • Save jdsimcoe/4240839 to your computer and use it in GitHub Desktop.

Select an option

Save jdsimcoe/4240839 to your computer and use it in GitHub Desktop.
XSLT Title Case
<!--
Title Case
<xsl:variable name="CatName">
<xsl:call-template name="TitleCase">
<xsl:with-param name="text" select="translate(normalize-space($ypcategoryname),
'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz')" />
</xsl:call-template>
</xsl:variable>
-->
<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:choose>
<xsl:when test="$lastletter=' '">
<xsl:value-of select="translate($thisletter,'abcdefghijklmnopqrstuvwxyz',
'ABCDEFGHIJKLMNOPQRSTUVWXYZ')"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$thisletter"/>
</xsl:otherwise>
</xsl:choose>
<xsl:call-template name="TitleCase">
<xsl:with-param name="text" select="substring($text,2)"/>
<xsl:with-param name="lastletter" select="$thisletter"/>
</xsl:call-template>
</xsl:if>
</xsl:template>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment