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

RE: Replace function and apostrophes

Subject: RE: Replace function and apostrophes
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Thu, 17 Feb 2005 14:49:10 -0000
xsl replace function
&apos; is translated to ' by the XML parser before the XPath processor sees
it. So the XPath string literal is ''' which is clearly wrong. In fact,
there's no point using &apos here: you only need it when the attribute
delimiters are apostrophes.

XPath 2.0 allows the delimiter of a string literal to be doubled withing the
string, so you can write

"replace(., '''', '\\''')" 

Alternatively, use

select='replace(., "&apos;", "\\&apos;")'

or define the strings as variables:

<xsl:variable name="x" as="xs:string">'</xsl:variable>
<xsl:variable name="x" as="xs:string">\\'</xsl:variable>

select="replace(.,$x,$y)"

Michael Kay
http://www.saxonica.com/


> -----Original Message-----
> From: Andrew Welch [mailto:ajwelch@xxxxxxxxxxxxxxx] 
> Sent: 17 February 2005 14:35
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject:  Replace function and apostrophes
> 
> 
> I'm trying to replace all occurances of apostrophes with \' 
> as part of a
> variable's select statement:
> 
> <xsl:variable name="foo" select="replace(., '&apos;', '\\&apos;'"/>
> 
> This fails with "invalid character in expression '\'" - any 
> ideas on how
> to do this?
> 
> Thanks
> andrew 

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.