Re: [xsl] Apostrophe escaping in contains().

Subject: Re: [xsl] Apostrophe escaping in contains().
From: David Carlisle <davidc@xxxxxxxxx>
Date: Tue, 2 Dec 2003 17:30:08 GMT
>	I've searched the FAQs, and they report that I'm escaping the apostrophe 
> correctly.

No they don't: Your snippet is not well formed XML, so it will not have
got as far as the XSLT engine:

<xsl:when test="contains($text, '"&apos;"')> some stuff </xsl:when>
               ^                 ^

You can not have an " in an XML attribute that is delimuted by ", you
have to quote the " Although actually your attribute isn't delimited at
all it has a " at the start and nothing at the end

so to make that well formed XML you'd have to have
<xsl:when test="contains($text, '&quot;&apos;&quot;')"> some stuff </xsl:when>
But that means the XML parser would pass on the attribute value

contains($text, '"'"')

which is an Xpath error as you can't have a ' in a '-delimted XPath

So working backwards, you want the Xpath

contains($text, "'")

which you then need to put into an XML attribute, either like this
test="contains($text, &quot;'&quot;)"
or like this
test='contains($text, "&apos;")'
remember that as far as the XML parser is concerned, Xpath syntax is
nothing, you just follow the XML rules: either wrap it in " and quote
any contained ", or wrap it in ' and quote any contained '.



This e-mail has been scanned for all viruses by Star Internet. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:

 XSL-List info and archive:

Current Thread