[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] RE: string comparison
>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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|