Subject: RE: [xsl] string comparison From: "Andrew Welch" <awelch@xxxxxxxxxxxxxxx> Date: Thu, 6 Jun 2002 12:33:45 +0100 |
>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: [xsl] 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 |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] <oXygen/> XML Editor 1.1.9, Mihai Ionescu | Thread | Re: [xsl] string comparison, Corneanu Dan |
Re: [xsl] string comparison, Jeni Tennison | Date | Re: [xsl] Correlation between two x, John Sands |
Month |