Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert First character of each word to upper case

I have a String and I need to convert the first letter of each word to upper case and rest to lower case using xsl, For example,

Input String= dInEsh sAchdeV kApil Muk

Desired Output String= Dinesh Sachdev Kapil Muk

Although, I know I have to use translate function for the purpose but how can I translate the first charter of each word to Upper-case and rest all in lower- case using XSLT 1.0

Thanks

like image 245
dinesh028 Avatar asked Oct 29 '12 13:10

dinesh028


People also ask

What converts the first letter of each word into the upper case?

To use a keyboard shortcut to change between lowercase, UPPERCASE, and Capitalize Each Word, select the text and press SHIFT + F3 until the case you want is applied.

How do you capitalize the first character of each word in a string?

In JavaScript, we have a method called toUpperCase() , which we can call on strings, or words. As we can imply from the name, you call it on a string/word, and it is going to return the same thing but as an uppercase. For instance: const publication = "freeCodeCamp"; publication[0].

How do you uppercase first character?

To capitalize the first character of a string, We can use the charAt() to separate the first character and then use the toUpperCase() function to capitalize it.


1 Answers

Here's another short solution. It uses pure XSL-T 2.0. I know OP had a requirement for XSL-T 1.0, but since this page is ranked #1 on Google for 'xsl-t title case function' in 2015, this seems more relevant:

<xsl:function name="xx:fixCase">
    <xsl:param name="text" />
    <xsl:for-each select="tokenize($text,' ')">
        <xsl:value-of select="upper-case(substring(.,1,1))" />
        <xsl:value-of select="lower-case(substring(.,2))" />
        <xsl:if test="position() ne last()">
            <xsl:text> </xsl:text>
        </xsl:if>
    </xsl:for-each>
</xsl:function>

Where 'xx' is your own namespace.

like image 122
Richard Kennard Avatar answered Sep 22 '22 08:09

Richard Kennard