Subject: RE: [xsl] comparison of strings having single quote From: Pemmaraju Phani Kumar <pkumar3@xxxxxxxx> Date: Fri, 1 Mar 2002 16:28:02 +0100 |
Hello Jeni I have a further problem... how are we going to handle a case where my string has both double quotes and single quotes. I attach my previous mail for your reference. In that example if I have to check for -----S"RI's---- how do I do it. Can you plz let me know. Thanks in advance warm regards Phani -----Original Message----- From: Jeni Tennison [mailto:jeni@xxxxxxxxxxxxxxxx] Sent: Friday, February 15, 2002 4:30 PM To: Pemmaraju Phani Kumar Cc: 'XSL-List@xxxxxxxxxxxxxxxxxxxxxx' Subject: Re: [xsl] comparison of strings having single quote Hi Phani, > I have the following xml & xsl files. I would like to get the ARTIST > which has only - Sri's -. How to do it. The main problem is with the > single quote handling. The when match condition given below fails. I notice that you're using WD-xsl rather than XSLT. You should upgrade to using XSLT as soon as you can. Details are in the MSXML FAQ at http://www.netcrucible.com/. The single-quote problem will occur in XSLT as well, though. Let's concentrate first on the XPath that you want to create. You've tried: ARTIST = 'Sri's' but this doesn't work because the single quote in the middle of the string is interpreted as ending the string. There's no way to escape characters in XPath, but you can use either single or double quotes around literal strings. So you have to do: ARTIST = "Sri's" That's the XPath that you want. Now you have to worry about putting that into an attribute value in XSLT. XSLT is XML, so you can't just do: test="ARTIST = "Sri's"" because the double quote that you need in the XPath expression will match the double quote that starts the attribute value, and you'll get an error. Fortunately, there *is* a ways of escaping characters in XML, so you can get around this problem by escaping the double quotes in the attribute value with " as follows: test="ARTIST = "Sri's"" Alternatively, you can use single quotes around the attribute value rather than double quotes. If you use single quotes, then the single quote in the attribute value has to be escaped with ' as follows: test='ARTIST = "Sri's"' Either of these will work. Cheers, Jeni --- Jeni Tennison http://www.jenitennison.com/ -----Original Message----- From: Pemmaraju Phani Kumar [mailto:pkumar3@xxxxxxxx] Sent: Friday, February 15, 2002 4:00 PM To: 'XSL-List@xxxxxxxxxxxxxxxxxxxxxx' Subject: [xsl] comparison of strings having single quote Hi I have the following xml & xsl files. I would like to get the ARTIST which has only - Sri's -. How to do it. The main problem is with the single quote handling. The when match condition given below fails. Thanks Phani <---xml file begin---> <?xml version="1.0" encoding="ISO8859-1" ?> <CATALOG> <CD> <TITLE>Maharaja</TITLE> <ARTIST>Kumars</ARTIST> <COUNTRY>India</COUNTRY> <COMPANY>MGM</COMPANY> <PRICE>10.90</PRICE> <YEAR>1985</YEAR> </CD> <CD> <TITLE>King Kong</TITLE> <ARTIST>Sri's</ARTIST> <COUNTRY>USA</COUNTRY> <COMPANY>Tseries</COMPANY> <PRICE>20</PRICE> <YEAR>1995</YEAR> </CD> <CD> <TITLE>PA </TITLE> <ARTIST>Sri's </ARTIST> <COUNTRY>USA</COUNTRY> <COMPANY>Baan </COMPANY> <PRICE>72000</PRICE> <YEAR>2002</YEAR> </CD> <CD> <TITLE>Bad</TITLE> <ARTIST>Michael Jackson </ARTIST> <COUNTRY>USA</COUNTRY> <COMPANY>MGM</COMPANY> <PRICE>20.00</PRICE> <YEAR>1985</YEAR> </CD> </CATALOG> <---xml file ends--> <---xsl file begin---> <?xml version='1.0'?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl"> <xsl:template match="/"> <html> <body> <table border="2" bgcolor="yellow"> <tr> <th>Title</th> <th>Artist</th> </tr> <xsl:for-each select="CATALOG/CD" order-by=" + ARTIST"> <tr> <xsl:choose> <xsl:when match=".[ARTIST='Sri's']"> <td bgcolor="#ff0000"><xsl:value-of select="TITLE"/></td> <td bgcolor="#ff0000"><xsl:value-of select="ARTIST"/></td> </xsl:when> <xsl:otherwise> <td><xsl:value-of select="TITLE"/></td> <td><xsl:value-of select="ARTIST"/></td> </xsl:otherwise> </xsl:choose> </tr> </xsl:for-each> </table> </body> </html> </xsl:template> </xsl:stylesheet> <---xsl file ends---> XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] LOOP-LIMIT, Hans Huber | Thread | Re: [xsl] comparison of strings hav, Jeni Tennison |
Re: [xsl] LOOP-LIMIT, David B. Bitton | Date | Re: [xsl] comparison of strings hav, Jeni Tennison |
Month |