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

RE: Selecting case insensitively

Subject: RE: Selecting case insensitively
From: "Doug Howell" <doug@xxxxxxxxxxxxxxxxxxxx>
Date: Sun, 13 Aug 2000 15:18:46 -0400
doug howell
Thanks, Jeni. You're right, I did mean xsl:apply-templates. Thanks for the
suggestion. I hadn't read up on the translate function yet, so thanks so
much for pointing out this possibility. I'll try it out and let you know.

Here is the function I'm using in the HTML page which loads the XML/XSL
docs, followed by the XSL code:

******************************
function select(strSearchTerm) {

//  possible parameter passed to this function:
'/glossary/entry[contains(\'name\',\'z\')]'

  // get text typed by user
  if (strSearchTerm == ""){
	var strNodeToSelect = "/glossary/entry"; // if user hasn't typed anything,
show all entries
  }
  else { // otherwise, get all entries that match what the user typed
   var strNodeToSelect = "/glossary/entry[contains(term,'" + strSearchTerm +
"')]";
   //alert(strNodeToSelect);
  }
  // get a reference to the 'select' attributes from
  // the 'xsl:apply-templates element' in the root template
  var objSelectNode =
gobjXSL.selectSingleNode("//xsl:apply-templates/@select");

  // change the attribute value to the specified XPath value
  objSelectNode.nodeValue = strNodeToSelect;

  // perform the transformation
  strResult = gobjXML.transformNode(gobjXSL);

  // and update the contents of the DIV element
  gobjResults.innerHTML = strResult;
}
**************************
<xsl:template match="/">
      <xsl:apply-templates select="/glossary/entry">
       <xsl:sort select="term" order="ascending"/>
      </xsl:apply-templates>
 </xsl:template>

 -----Original Message-----
From: 	Jeni Tennison [mailto:jeni@xxxxxxxxxxxxxxxx]
Sent:	Friday, August 11, 2000 3:47 PM
To:	Doug Howell
Cc:	XSL-List@xxxxxxxxxxxxxxxx
Subject:	Re: Selecting case insensitively

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

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.