stringxpathxsltcase-conversion

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


How do you do case conversion in XSL?

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

Solution

  • 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>