Re: [xsl] Changing case using translate()

Subject: Re: [xsl] Changing case using translate()
From: Jeni Tennison <mail@xxxxxxxxxxxxxxxx>
Date: Thu, 15 Feb 2001 14:04:23 +0000
Hi Andrew,

> As I understand it, case conversion is done using
>
> translate(xxxx,abcdefghijklmnopqrstuvwxyz,ABCDEFGHIJKLMNOPQRSTUVWXYZ)

Well, you have to have quotes around the alphabets so that they're
recognised as strings, but basically you're right.

To save time, I'd save the alphabets in variables:

<xsl:variable name="uppercase" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'" />
<xsl:variable name="lowercase" select="'abcdefghijklmnopqrstuvwxyz'" />

> Im trying to incorporate it into the following line of code, to allow
> case-independant searching:
>
> <xsl:for-each select="TBD/business[contains(*[local-name() = $param1],
$param2)]">
>
> By converting both params to uppercase it should allow, for example,
> 'rising' to match 'Rising Sun'.

They should go around both of the values that you're comparing. You
don't want to translate $param1 because that will change which child
of the business element you're testing.  Rather, you want to
translate:

  *[local-name() = $param1]

(i.e. the value of the business element's child called $param1) with:

  translate(*[local-name() = $param1], $lowercase, $uppercase)

The second value is $param2, so changing that to uppercase can be done
with:

  translate($param2, $lowercase, $uppercase)

Putting this together, you get the select expression:

  TBD/business[contains(translate(*[local-name() = $param1],
                                  $lowercase, $uppercase),
                        translate($param2, $lowercase, $uppercase))]

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