lower case the first character of a string using o

2019-02-12 07:56发布

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

标签: xslt xslt-1.0
4条回答
We Are One
2楼-- · 2019-02-12 08:35

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.

查看更多
孤傲高冷的网名
3楼-- · 2019-02-12 08:36

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))
查看更多
我想做一个坏孩纸
4楼-- · 2019-02-12 08:43

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

查看更多
劫难
5楼-- · 2019-02-12 08:49

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))"/>
查看更多
登录 后发表回答