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
2009-07-30 14:49:38
+1 ;-)
Tomalak
2009-07-30 14:53:12
String manipulation in XSLT, what a joke.
Welbog
2009-07-30 14:54:12
Asker's name looks vaguely French... what happens to é ? (sorry, I couldn't resist...)
AakashM
2009-07-30 14:55:57
@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
2009-07-30 15:12:56
+1
A:
XPath 2.0 has fn:upper-case()
, which also does Unicode correct case mappings.
Tomalak
2009-07-30 14:52:41
+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
2009-07-30 14:54:40
+1, though it's the same strategy as my answer keeping variables of the letters is certainly a more reusable solution.
Welbog
2009-07-30 15:13:39
A:
I want to change the uppercase to lowercase in the html file completely using xslt..can anyone help me
vignesh
2010-10-11 12:41:07