RE: [xsl] Capitalizing content of a variable

Subject: RE: [xsl] Capitalizing content of a variable
From: Joerg Pietschmann <joerg.pietschmann@xxxxxx>
Date: Thu, 09 Aug 2001 10:29:54 +0200
"Nitin Dutt Mathur" <nitin@xxxxxxxxxxxx> wrote:
[snip]
> <component ..>
> <xsl:variable name="foo">
> <!-- do dome processing to get the value of variable-->
> </xsl:variable>
> <!-- At this point I want to have the capitalize value of the contents of
> foo variable (may be in same variable or in some other variable. -->
> </component>
> 
> Since at the time of transforming the contents of variable I don't know the
> exact contents hence I unable to figure out how to use translate function.
> 
You have to split the string using substring(), translate the substring
containing the first character, and concat the results.
Try
  <xsl:variable name="bar"
    select="concat(translate(substring($foo,1,1),'abc...','ABC...'),
                   substring($foo,2))"/>

In order to keep it more readable, often variables are declared
and used for the constant strings:
  <xsl:variable name="lower" select="'abc...'"/>
  <xsl:variable name="upper" select="'ABC...'"/>
  ...
    translate(...,$lower,$upper)
  ...

You may also include non-ASCII characters in the translation string, if
necessary. The following can be used to upcase german umlauts:
  <xsl:variable name="lower" select="'&#xE4;&#xF6;&#xFC;'"/>
  <xsl:variable name="upper" select="'&#xC4;&#xD6;&#xDC;'"/>
  
HTH
J.Pietschmann

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread