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

RE: string comparison

Subject: RE: string comparison
From: "Andrew Welch" <awelch@xxxxxxxxxxxxxxx>
Date: Thu, 6 Jun 2002 12:33:45 +0100
xsl variable string compare
>How can I select all the contacts which contain the string 
>"corneanu" or "Corneanu" or "cOrneanu" etc. in the <name> 
>child? Is there something like the 'like()' function from SQL?

Sort of.  You first need to convert everything to uppercase (or
lowercase), then test to see if its in there.

So,its usually best to set up the global variables (to save your
fingers):

<xsl:variable name="lowercase" select="'abcdefg... and so on'"/>
<xsl:variable name="uppercase" select="'ABCDEFG... and so on'"/>

You then need to convert both the search string and the text content to
uppercase (to negate case)

translate(name,$lowercase,$uppercase)
translate($searchString,$lowercase,$uppercase)

and then see if the searchString is in the name element

contains(name,$searchString)

So if you then put it all together, you might get something like this.
Here Ive used a param to accept the search string (defaulting to
'corneanu') and an extra variable holding it in uppercase.

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:variable name="lowercase" select="'abcdefghijklmnopqrstuvwxyz'"/>
<xsl:variable name="uppercase" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'"/>
<xsl:param name="searchString" select="'corneanu'"/>
<xsl:variable name="upperSearchString"
select="translate($searchString,$lowercase,$uppercase)"/>

<xsl:template match="/">
  <xsl:for-each
select="//contact[contains(translate(name,$lowercase,$uppercase),$upperS
earchString)]">
    <xsl:apply-templates select="."/>
  </xsl:for-each>
</xsl:template>

<xsl:template match="name">
  <xsl:value-of select="."/>
</xsl:template>

</xsl:stylesheet>


Honestly, it looks more way more complicated than it really is.

have fun!

cheers
andrew




-----Original Message-----
From: Corneanu Dan [mailto:cdan@xxxxxxxxxxx]
Sent: 06 June 2002 11:42
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject:  string comparison


Hi, 
 I have a document made up from a collection of addresses like this:  
<address-book> 
 <contact> 
	<name>Dan Corneanu Cornel</name>  
       .....
 </contact> 
 <contact> 
	 <name>Florin Corneanu</name> 
	 ...... 
 </contact> 
    ........ 
</address-book> 

How can I select all the contacts which contain the string 
"corneanu" or "Corneanu" or "cOrneanu" etc. in the <name> 
child? Is there something like the 'like()' function from SQL?

Best regards, Dan.




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





---
Incoming mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.350 / Virus Database: 196 - Release Date: 17/04/2002
 

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.350 / Virus Database: 196 - Release Date: 17/04/2002
 

 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.