views:

6215

answers:

3

How do you do case conversion in XSL?

<xsl:variable name="upper">UPPER CASE</xsl:variable>
<xsl:variable name="lower" select="???"/>
+2  A: 

upper-case(string) and lower-case(string)

Link with more info

Eric Petroelje
+5  A: 

XSLT 2.0 has upper-case() and lower-case() functions. In case of XSLT 1.0, you can use translate():

translate("xslt", "abcdefghij...z", "ABCDEFGHIJ...Z")
Anton Gogolev
+25  A: 

In XSLT 1.0 the upper-case() and lower-case() functions are not available. If you're using a 1.0 stylesheet the common method of case conversion is translate():

<xsl:variable name="smallcase" select="'abcdefghijklmnopqrstuvwxyz'" />
<xsl:variable name="uppercase" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'" />


<xsl:template match="/">
  <xsl:value-of select="translate(doc, $smallcase, $uppercase)" />
</xsl:template>
Jweede
2 minutes too late. This is what I get for going into detail. :)
Jweede
Is there a Unicode version? This solution is not going to work with funny characters...
mjs
For XSLT 1.0 you'd have to add more to the smallcase/uppercase variables or use an extension function.
Jweede
If you decided not to use the extention function you might be able to make a complete list using the Unicode Character Database: http://www.unicode.org/Public/UNIDATA/UCD.html
Jweede