[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: String Case Conversion: Title Case

Subject: Re: String Case Conversion: Title Case
From: Mukul Gandhi <gandhi.mukul@xxxxxxxxx>
Date: Wed, 7 Oct 2009 14:32:52 +0530
Re:  String Case Conversion: Title Case
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))), ' ')" />
</xsl:function>

and call it like:

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

please make sure, that a namespace is declared as well (e.g,
xmlns:my="http://www.example.com/myfuncs").

For e.g, this function when called with argument, heLLO worLD produces
output:
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>
wrote:
>
> 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



--
Regards,
Mukul Gandhi

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.