i am not able to pick apostrophe sign with below code
exists(//ns1:name[text()='Hurricane's Grill Darling Harbour']).
Getting error message: RuntimeException:net.sf.saxon.trans.XPathException: XPath syntax error at char 33 on line 2 in {...name[text()='Hurricane's Gr...}:
expected "]", found name "s
In XPath 2.0 an apostrophe or a double quote can be escaped by simply doubling that character. See rules [75] and [76] here: http://www.w3.org/TR/xpath20/#terminal-symbols
Use:
exists(//ns1:name[text()='Hurricane''s Grill Darling Harbour'])
XSLT 2.0 - based verification:
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:ns1="ns1">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:template match="/">
<xsl:sequence
select="exists(//ns1:name[text()='Hurricane''s Grill Darling Harbour'])"/>
</xsl:template>
</xsl:stylesheet>
When this transformation is applied on the following XML document:
<ns1:name xmlns:ns1="ns1">Hurricane's Grill Darling Harbour</ns1:name>
the wanted, correct result is produced:
true
In case you only can use an XPath 1.0 expression within an XML document and the string contains both kinds of quotes, use:
boolean(//ns1:name
[text()=concat('Hurricane "Mathew"', " strength's value")])
Here is a full XSLT 1.0 - based verification:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:ns1="ns1">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:template match="/">
<xsl:value-of select=
"boolean(//ns1:name
[text()=concat('Hurricane "Mathew"', " strength's value")])"/>
</xsl:template>
</xsl:stylesheet>
When this transformation is applied on the following XML document:
<ns1:name xmlns:ns1="ns1">Hurricane "Mathew" strength's value</ns1:name>
the wanted, correct result is produced:
true