Re: Changing XML Case using XSL/DOM - MSXML3

Subject: Re: Changing XML Case using XSL/DOM - MSXML3
From: Jeni Tennison <mail@xxxxxxxxxxxxxxxx>
Date: Wed, 8 Nov 2000 22:41:22 +0000
Ciaran,

>         Is anyone aware of a way in which I can change the
> case of my XML content from Uppercase to Lowercase. I was
> looking at three possible solutions:
>
> 1. Use of stylesheets to perform this function 
> but I don't want to process each individual element.
>
> 2. Manipulating the DOM in the code.
>
> 3. Search & Replace before loading the content into the DOM.

Do you mean the actual textual content of the XML, the element and
attribute names, or both? Are your files always going to be English or
do you need to worry about accented characters, other languages and so
on?

If you don't want to just change everything, then it's probably better
to use either the DOM or a stylesheet because both of these have
already parsed the XML and can identify which bits of the XML are
content and which are element or attribute names (and so on).  If you
want to change all the text into lowercase, then use option 3.

If you are trying to take into account all the uppercase and lowercase
characters that might be used in a variety of languages, then you're
probably best to avoid XSLT because the translate() function is fairly
limited whereas I guess there are likely to be functions in your
implementation language that you can use more easily.  If you're only
using a-z, and only changing element and attribute names, then you can
use:

<xsl:variable name="uc" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'" />
<xsl:variable name="lc" select="'abcdefghijklmnopqrstuvwxyz'" />

<xsl:template match="*">
  <xsl:element name="{translate(name(), $uc, $lc)}">
    <xsl:for-each select="@*">
      <xsl:attribute name="{translate(name(), $uc, $lc)}">
        <xsl:value-of select="." />
      </xsl:attribute>
    </xsl:for-each>
    <xsl:apply-templates />
  </xsl:element>
</xsl:template>

Or, as you're using MSXML, you can always create your own translate
function in VBScript or JScript with msxsl:script and use that.

I hope that helps,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/



 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread