Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > How can I change the case of the first letter in the string in xslt

Reply
Thread Tools

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

 
 
f
Guest
Posts: n/a
 
      11-26-2003
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
 
Reply With Quote
 
 
 
 
Dimitre Novatchev
Guest
Posts: n/a
 
      11-27-2003

"f" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) om...
> 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


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: change the first letter into uppercase (ask) Dennis Lee Bieber Python 0 10-20-2012 07:30 PM
Re: change the first letter into uppercase (ask) Zero Piraeus Python 0 10-20-2012 05:03 AM
Re: change the first letter into uppercase (ask) Dave Angel Python 0 10-20-2012 04:21 AM
How can i get the first letter of this string duc nguyen Ruby 9 03-04-2011 03:11 AM
First letter in upper case dave ASP General 3 06-24-2004 01:54 PM



Advertisments