Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

lower case the first character of a string using only xslt 1.0

Tags:

xslt

xslt-1.0

I have seen patterns for translating a string into lower (or upper case) using the translate function for folks stuck using xslt 1.0.

Is there a elegant way of just making the first letter of a string lowercase?

TestCase => testCase
like image 548
Atlas1j Avatar asked Mar 17 '09 17:03

Atlas1j


People also ask

How do you translate in XSLT?

translate( ) is a versatile string function that is often used to compensate for missing string-processing capabilities in XSLT. Here you use the fact that translate( ) will not copy characters in the input string that are in the from string but do not have a corresponding character in the to string.


2 Answers

If your string were, for example, in an attribute called name:

<xsl:value-of select="concat(translate(substring(@name, 1, 1), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz'), substring(@name, 2))"/>
like image 138
Ben Blank Avatar answered Oct 10 '22 09:10

Ben Blank


You should be able to combine substring and concat with translate to do it like so:

concat(translate(substring(s,1,1), $smallcase, $uppercase),substring(s,2))
like image 43
MarkusQ Avatar answered Oct 10 '22 10:10

MarkusQ