Camel Case strings in XSLT I have a situation where I am receiving data from a web service and the data is in all caps.  I have to convert to HTML and format for display.  In this case, we need the string to be normalized.  The XML we receive has the possibility, and most of the time is, large, sometimes being over a MB in size.  Performance is an issue.  

I have the below templates that I use for normalizing the string.  I'm limited to XSLT 1.0.

&lt;xsl:template name="CamelCase"&gt;
    &lt;xsl:param name="text"/&gt;

    &lt;xsl:variable name="checkNBSP" select="translate($text, '&amp;nbsp;', ' ')"/&gt;
    &lt;xsl:variable name="check160" select="translate($checkNBSP, '&amp;#160;', ' ')"/&gt;

    &lt;xsl:choose&gt;
        &lt;xsl:when test="contains($check160,' ')"&gt;
            &lt;xsl:call-template name="CamelCaseWord"&gt;
                &lt;xsl:with-param name="text" select="substring-before($check160,' ')"/&gt;
            &lt;/xsl:call-template&gt;
            &lt;xsl:text&gt; &lt;/xsl:text&gt;
            &lt;xsl:call-template name="CamelCase"&gt;
                &lt;xsl:with-param name="text" select="substring-after($check160,' ')"/&gt;
            &lt;/xsl:call-template&gt;
        &lt;/xsl:when&gt;
        &lt;xsl:otherwise&gt;
            &lt;xsl:call-template name="CamelCaseWord"&gt;
                &lt;xsl:with-param name="text" select="$check160"/&gt;
            &lt;/xsl:call-template&gt;
        &lt;/xsl:otherwise&gt;
    &lt;/xsl:choose&gt;
&lt;/xsl:template&gt;

&lt;xsl:template name="CamelCaseWord"&gt;
    &lt;xsl:param name="text"/&gt;
    &lt;xsl:value-of select="translate(substring($text,1,1),'abcdefghijklmnopqrstuvwxyz','ABCDEFGHIJKLMNOPQRSTUVWXYZ')" /&gt;
    &lt;xsl:value-of select="translate(substring($text,2,string-length($text)-1),'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz')" /&gt;
&lt;/xsl:template&gt;


I initially found the below template on Stack Overflow and made some slight modifications to it to meet my purposes.  Is this way the optimal way to format the string, or can this be cleaned up?
The solution looks near optimal to me. If performance is an issue I would suggest the two following minor modifications:


The cleaning of the string regarding the special characters (&amp;nbsp; and &amp;#160;) is done at every calling level. You could introduce a third template called CamelCaseRecursive which would look like CamelCase but it would not contain the cleaning methods. So, CamelCase would be official external interface which would call CamelCaseRecursive which would call itself recursively. This change may save the more time the more words a text has on the average.
In CamelCaseWord you could contract the two &lt;xsl:value-of&gt; tags into one by using the concat() function: 

&lt;xsl:value-of 
    select="concat(translate(substring($text,1,1),
                             'abcdefghijklmnopqrstuvwxyz',
                             'ABCDEFGHIJKLMNOPQRSTUVWXYZ'), 
                   ' ',
                   translate(substring($text,2,string-length($text)-1), 
                             'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 
                             'abcdefghijklmnopqrstuvwxyz')
                   )" /&gt;



I would assume that the performance gains will be minimal with today's highly optimized XSLT processors. However, if this actually helps it would be great to learn about it!