This following template in xslt can be used to change text to its title case:
<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>
And it can be called in other template as below:
<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>
Great. Was able to modify this for my own purposes. Much appreciated - thanks.
Thanks, this little snippet just saved me a lot of work. Cheers
Great, I'm new to XSLT and flailing a bit. This helped me get something done and helped me learn.
This is what I need, but I can't get it to display the values. Can you please help?