[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: "Andrew Welch" <andrew@xxxxxxxxxxxxxxxxxxxxxxx>
Date: Thu, 15 Feb 2001 14:29:45 -0000
contains translate
Thanks, that works perfectly - however I have one further, slightly
un-related issue:

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.


Searching for 'A' on the above xml produces no results.


However, searching for 'A' here returns the required result because there is
only a single <keyword> element.

Is this a problem with the structure of my xml files, or is there a way of
modifying the search line to take into account multiple elements with the
same name???

Thanks once again for all the help



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],
> 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

  *[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

  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 Tennison

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

Current Thread


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.
First Name
Last Name
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.