xsl-list
[Top] [All Lists]

RE: Escaping quotes in XPath expressions

2003-11-15 06:48:11

<xsl:variable name="quot">"</xsl:variable>
<xsl:variable name="apos">'</xsl:variable>
<xsl:value-of select="translate(., $quot, $apos)"/>

Michael Kay

-----Original Message-----
From: owner-xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com 
[mailto:owner-xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com] On Behalf Of 
yguaba(_at_)yahoo(_dot_)com(_dot_)br
Sent: 15 November 2003 12:55
To: XSL-List(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: [xsl] Escaping quotes in XPath expressions


Hello all,

Can anyone please tell me how I can escape a single-quote in 
an XPath expression 
such as the one below?

<xsl:value-of select="translate(normalize-space(.), 'x', 'y')"/>

If I use 'x' and 'y' as the search and replace arguments, 
everything works well. But I 
need to search for single-quotes and replace them with 
backslash + single-quote. In 
other words, my XPath expression would look something like this:

translate(normalize-space(.), ''', '\'')

Except, of course, that I can't use a single-quote 
(character) between two single-quotes 
(string delimiters). Backslashes don't escape anything, of 
course, and using XML 
entities (&quot;) inside the search and replace strings won't 
work either.

But I just feel there must be a way to do this...

Thanks,

Erik

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



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