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

RE: comparison of strings having single quote

Subject: RE: comparison of strings having single quote
From: Pemmaraju Phani Kumar <pkumar3@xxxxxxxx>
Date: Fri, 1 Mar 2002 16:28:02 +0100
xslt escape single quote
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:  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 &quot; as follows:

  test="ARTIST = &quot;Sri's&quot;"

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 &apos; as follows:

  test='ARTIST = "Sri&apos;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:  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

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.