11

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
Community
  • 1
  • 1
Atlas1j
  • 2,442
  • 3
  • 27
  • 35

4 Answers4

14

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))"/>
Ben Blank
  • 54,908
  • 28
  • 127
  • 156
3

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))
MarkusQ
  • 21,814
  • 3
  • 56
  • 68
0

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.

Richard
  • 106,783
  • 21
  • 203
  • 265
0

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

Benjamin Autin
  • 4,143
  • 26
  • 34