Re: [xsl] String Case Conversion: Title Case

Subject: Re: [xsl] String Case Conversion: Title Case
From: Mukul Gandhi <gandhi.mukul@xxxxxxxxx>
Date: Wed, 7 Oct 2009 14:32:52 +0530
you might use a custom XSLT (2.0) function like below:

<xsl:function name="my:titleCase" as="xs:string">
    <xsl:param name="str" as="xs:string" />

    <xsl:sequence select="string-join(for $x in tokenize($str,'\s')
return concat(upper-case(substring($x, 1, 1)),
lower-case(substring($x, 2))), ' ')" />

and call it like:

<xsl:value-of select="my:titleCase($str)" />

please make sure, that a namespace is declared as well (e.g,

For e.g, this function when called with argument, heLLO worLD produces
Hello World

You could also think, about cultural issues as pointed by Mike. But I
think, the above example could be a simple algorithm for transforming
English phrases, where you just want to capitalize the first letter of
the word, and keep rest of letters in the word as small case.

On Wed, Oct 7, 2009 at 12:34 PM, Ramkumar <ramkumar@xxxxxxxxxxxxxxxxxx>
> Hi List,
> I have used upper-case and lower-case methods in xslt2.0. But I like to
> know, how to convert Title-Case/Upper-Lower Case. Could any one share with
> me the logic for this.
> Ex:
> B Upper Case: UPPER CASE
> B Lower Case: lower case
> B Title Case: Title Case
> Regards,
> Ramkumar
> R&D - Software Engineer
> PreMedia Global Ltd

Mukul Gandhi

Current Thread