Re: Selecting case insensitively

Subject: Re: Selecting case insensitively
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Fri, 11 Aug 2000 20:47:09 +0100
Doug,

>I'm developing an XML glossary, and want to update the "select" attribute of
>the xsl:template based on what people type (a few characters) in a search
>text input field. Is there any way to select case-_in_sensitively? Do I need
>to write functions which create different mixed-case versions of what's
>typed, and then use these versions with "or" in the select predicate/filter?
>Or is there an easier way (I hope)?

I'm not exactly sure what you're doing: there's no 'select' attribute on
xsl:template, for example (you probably mean xsl:apply-templates?).

One good method for testing in a case-insensitive way is to translate both
the things you're testing into lowercase (or uppercase) and testing for
equality or whatever with the translated strings.

Define variables for uppercase and lowercase letters:

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

Then use the translate() function to translate the two things you're
comparing into lowercase and compare them:

  translate($word1, $uppercase, $lowercase) =
  translate($word2, $uppercase, $lowercase)

You can put this test within a predicate in an XPath, of course.

I hope that approximates to what you were after,

Jeni

Dr Jeni Tennison
Epistemics Ltd * Strelley Hall * Nottingham * NG8 6PE
tel: 0115 906 1301 * fax: 0115 906 1304 * email: jeni.tennison@xxxxxxxxxxxxxxxx


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


Current Thread