[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Changing case using translate()

Subject: Re: Changing case using translate()
From: Jeni Tennison <mail@xxxxxxxxxxxxxxxx>
Date: Thu, 15 Feb 2001 17:46:12 +0000
contains translate
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.

Oh.

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
$param1.

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
insensitively).

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

all the business elements:

  TBD/business

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
separately:

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

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

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

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.