Created
December 8, 2012 16:01
-
-
Save jdsimcoe/4240839 to your computer and use it in GitHub Desktop.
XSLT Title Case
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!-- | |
| 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