How can I change the case of the first letter in the string in xslt

F

f

Suppose I have a xml

<class>
<Name>Good</Name>
<Name>bad</Name>
</class>

I hava the xsl

<xsl:template match="Class">
<xsl:for-each select=".\Name">
<xsl:value-of select=".\">
</xsl:for-each>
</xsl:template>

it will print out

Good
bad.

But what I want is:

good
Bad

How can I change the case of the first letter?

Thanks,

qq
 
D

Dimitre Novatchev

f said:
Suppose I have a xml

<class>
<Name>Good</Name>
<Name>bad</Name>
</class>

I hava the xsl

<xsl:template match="Class">
<xsl:for-each select=".\Name">

This is wrong -- probably you meant just "Name"
<xsl:value-of select=".\">

This is wrong -- probably you meant just "."
</xsl:for-each>
</xsl:template>

it will print out

Good
bad.

But what I want is:

good
Bad

How can I change the case of the first letter?


Use:
concat(translate(substring(., 1, 1),
concat($lower, $upper),
concat($upper, $lower)
),
substring(., 2)
)

where $lower and $upper are xsl:variable s defined like this:

<xsl:variable name="lower" select="'abcdefghijklmnopqrstuvwxyz'"/>

<xsl:variable name="upper" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'"/>



=====
Cheers,

Dimitre Novatchev.
http://fxsl.sourceforge.net/ -- the home of FXSL
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,225
Members
46,815
Latest member
treekmostly22

Latest Threads

Top