views:

3103

answers:

4

I am using an XSLT stylesheet to create an Excel document from an XML file. One of the values that I am pulling in I want to display as upper case. How is this possible?

+5  A: 

You can use the translate() function in XSLT 1.0:

<xsl:value-of select="translate(//some-xpath,
                                'abcdefghijklmnopqrstuvwxyz',
                                'ABCDEFGHIJKLMNOPQRSTUVWXYZ')" />

If you're lucky enough to have access to XSLT 2.0, you can use the upper-case() function:

<xsl:value-of select="upper-case(//some-xpath)"/>

See the XPath function reference page for more details.

Welbog
+1 ;-)
Tomalak
String manipulation in XSLT, what a joke.
Welbog
Asker's name looks vaguely French... what happens to é ? (sorry, I couldn't resist...)
AakashM
@AakashM: That's the problem with the `translate()` function. You have to specify all of these things yourself. `upper-case()` is a much better option but it's not supported widely enough.
Welbog
+1  A: 

XPath 2.0 has fn:upper-case(), which also does Unicode correct case mappings.

Tomalak
+8  A: 

XSLT 2.0 has fn:upper-case() and fn:lower-case() functions. However in case you are using of XSLT 1.0, you can use translate():

<xsl:template match="/">
  <xsl:value-of select="translate(doc, $smallcase, $uppercase)" />
</xsl:template>
<xsl:variable name="smallcase" select="'abcdefghijklmnopqrstuvwxyz'" />
<xsl:variable name="uppercase" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'" />
David Christiansen
Damn, Too slow!
David Christiansen
+1, though it's the same strategy as my answer keeping variables of the letters is certainly a more reusable solution.
Welbog
A: 

I want to change the uppercase to lowercase in the html file completely using xslt..can anyone help me

vignesh