[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] RE: Replace function and apostrophes
' 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@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(., ''', '\\''"/> > > This fails with "invalid character in expression '\'" - any > ideas on how > to do this? > > Thanks > andrew
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|