Question

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
Was it helpful?

Solution

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))"/>

OTHER TIPS

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))

Use the XPath translate function, having separated the string into first character and the rest. This will require somewhat long winded XSLT using multiple variables to hold intermediate results.

XSLT has a substring function, so you could use that pattern with the substring function to get what you want.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top