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

Discussion in 'XML' started by f, Nov 26, 2003.

  1. f

    f Guest

    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
    f, Nov 26, 2003
    #1
    1. Advertising

  2. "f" <> wrote in message
    news:...
    > 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
    Dimitre Novatchev, Nov 27, 2003
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. vertigo

    big letter -> small letter

    vertigo, Jul 6, 2004, in forum: Python
    Replies:
    4
    Views:
    745
    Reinhold Birkenfeld
    Jul 6, 2004
  2. Tony Meyer

    RE: big letter -> small letter

    Tony Meyer, Jul 6, 2004, in forum: Python
    Replies:
    0
    Views:
    495
    Tony Meyer
    Jul 6, 2004
  3. Andrew McNamara

    Re: big letter -> small letter

    Andrew McNamara, Jul 6, 2004, in forum: Python
    Replies:
    2
    Views:
    744
    Scott David Daniels
    Jul 6, 2004
  4. dave

    First letter in upper case

    dave, Jun 24, 2004, in forum: ASP General
    Replies:
    3
    Views:
    140
    Dave Anderson
    Jun 24, 2004
  5. duc nguyen
    Replies:
    9
    Views:
    143
    7stud --
    Mar 4, 2011
Loading...

Share This Page