How can I convert a string to upper- or lower-case with XSLT?

mjs picture mjs · Feb 25, 2009 · Viewed 170.3k times · Source

How do you do case conversion in XSL?

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

Answer

Jon W picture Jon W · Feb 25, 2009

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="lowercase" select="'abcdefghijklmnopqrstuvwxyz'" />
<xsl:variable name="uppercase" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'" />


<xsl:template match="/">
  <xsl:value-of select="translate(doc, $lowercase, $uppercase)" />
</xsl:template>