This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

RE: Capitalizing content of a variable


"Nitin Dutt Mathur" <nitin@pscindia.com> 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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]