xsltxpathuppercasemsxml4

XSLT/XPath : No upper-case function in MSXML 4.0?


I try to use upper-case() in an XPATH, my parser is MSXML 4.0, and I get :

upper-case is not a valid XSLT or XPath function.

Is it really not implemented ?


Solution

  • There are no functions in xslt 1.0 to convert to uppercase or lowercase. Instead do the following:

    If it is required in a lot of places:

    Declare these two xsl variables (this is to make the xslt more readable)

    <!-- xsl variables up and lo and translate() are used to change case -->
      <xsl:variable name="up" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'"/>
      <xsl:variable name="lo" select="'abcdefghijklmnopqrstuvwxyz'"/>
    

    And use them in your translate function to change the case

    <xsl:value-of select="translate(@name,$lo,$up)"/>
    

    If you need to use it in just one place, no need to declare variables

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