Reputation: 28730
I'll spare you the details because they would be needlessly confusing. Long story short, I'm using XSLT 1.0 to generate XSL documents, I'm trying to compare a variable to a literal string, and that string may contain quotes and apostrophes.
For the sake of simplicity, let's say that this literal is composed of two characters: a quote followed by an apostrophe. In reality, it can be any text really. Is there a simpler way to do this:
<xsl:if test="$var = concat('"', "'")">
than this?
<xsl:variable name="str">"'</xsl:variable>
<xsl:if test="$var = $str">
I have checked XPath's specs and there doesn't seem to be a way to escape characters, so the following would not work as desired:
<xsl:if test="$var = '"&apos;'">
Thanks!
Upvotes: 2
Views: 2053
Reputation: 101565
There's no way to do it neatly in XPath 1.0. In XPath 2.0, you can escape both kinds of quotes by doubling.
Upvotes: 2
Reputation: 23624
& quot;& amp;&(!)apos;
-looks much better, but what did you want to get?
In anyway: once I have written application that deals with producing of Javascript over XSLT.
The same problem with huge number of & quot;
,... we solved in 2 ways:
xsl:param
, $q
- looks shorter than & quot;
translate
' XPath function, make assumption '!'
- is a & quot;
, #
is a & amp;
..Upvotes: 1