' 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(., "'", "\\'")'
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(_at_)piper-group(_dot_)com]
Sent: 17 February 2005 14:35
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: [xsl] 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(., ''', '\\''"/>
This fails with "invalid character in expression '\'" - any
ideas on how
to do this?
Thanks
andrew
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail:
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--