[ACCEPTED]-XSLT Stylesheet: Changing text to upper case-uppercase

Accepted answer
Score: 55

XSLT 2.0 has fn:upper-case() and fn:lower-case() functions. However 2 in case you are using of XSLT 1.0, you can 1 use translate():

<xsl:template match="/">
  <xsl:variable name="smallcase" select="'abcdefghijklmnopqrstuvwxyz'" />
  <xsl:variable name="uppercase" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'" />
  <xsl:value-of select="translate(doc, $smallcase, $uppercase)" />
Score: 20

You can use the translate() function in XSLT 1.0:

<xsl:value-of select="translate(//some-xpath,
                                'ABCDEFGHIJKLMNOPQRSTUVWXYZ')" />

If 3 you're lucky enough to have access to XSLT 2 2.0, you can use the upper-case() function:

<xsl:value-of select="upper-case(//some-xpath)"/>

See the XPath function reference page for 1 more details.

Score: 3

XPath 2.0 has fn:upper-case(), which also does Unicode 1 correct case mappings.

Score: 2

Use an Assembly like this:

<msxsl:script implements-prefix="user" language="C#">

public string ToUpper(string stringValue)
    string result = String.Empty;

      result = stringValue.ToUpper(); 

    return result;

Call it as follows: select="user:ToUpper(//root/path)"

This 1 can be used in 1.0 or 2.0.

More Related questions