Jun 18 2006

ToLowerCase or ToUpperCase in XSLT

Category: XSLT, XPath, XMLBil@l @ 20:35

This is a simple sample to show you how to transform the content of an element in an XML file from lower/upper case to upper/lower case

First of all define a variable of the element as:

    <xsl:variable name="Title">
      <xsl:call-template name="ToLowerCase">
        <xsl:with-param name="Field" select="Title"/>
      </xsl:call-template>
    </xsl:variable>

Then define the Template that will do the transformation:

  <xsl:template name="ToLowerCase">
    <xsl:param name="Field" select="''"/>
    <xsl:value-of select='translate($Field,"ABCDEFGHIJKLMNOPQRSTUVWXYZ","abcdefghijklmnopqrstuvwxyz")'/>
  </xsl:template>

As you can see we are transforming all letters to lower case, the same can be done with a similar template to translate letters to upper case.

Hope this helps,

Regards

Tags:

Comments are closed