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
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.
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].
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With