Re: [xsl] Changing case using translate()

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

> The code
> TBD/business[contains(translate(*[local-name() = $param1],$lowercase,
> $uppercase),translate($param2, $lowercase, $uppercase)]
> works fine if there is only one child element of business, such as
> 'name'. However, each business node currently contains several
> <keyword> child nodes, that don't get picked up by the above. If I
> reduce the number of <keyword> nodes to one (for each business node)
> then it searches no problem.


That's different then, but actually it's a problem to do with the
contains() rather than the translate() - the contains() forces the
first argument to be a string, so within contains():

   *[local-name() = $param1]

will only pick the value of the *first* of business's children called

To get the effect you want, you actually want to look at all the
business elements, and select those for which there is any child
element called $param1 such that their value contains $param2 (case

Repeating that more slowly so that we can build an XPath:

all the business elements:


for which there is any child element called $param1:

  TBD/business[*[local-name() = $param1]]

such that their value contains $param2:

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

(case insensitively):

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

You could cut down on the size of this a bit (and improve its
efficiency) by getting a capitalised version of $param2 defined

<xsl:variable name="PARAM2"
              select="translate($param2, $lowercase, $uppercase)" />

and then:
  TBD/business[*[local-name() = $param1]
                [contains(translate(., $lowercase, $uppercase),

I hope that helps,


Jeni Tennison

 XSL-List info and archive:

Current Thread