Jump to: navigation, search

M2T-JET-FAQ/How do I put quotes in an XPath string?

Revision as of 11:43, 13 March 2009 by Pelder.ca.ibm.com (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)


How do I put single or double quotes into an XPath string?

I'd like to set a JET variable to the value 'ABC' (including the single quotes).


As of JET 0.9, you can make use of XPath quote escaping and/or quote escaping in JET tag attributes.

<%-- using doubled single quotes (') to indicate an literal single quote character --%>
<c:setVariable var="var" select="   '''ABC'''   "/>

To do double quotes ("ABC"), you could do either of the following:

<%-- surround the select attribute value with single quotes
  -- and using doubled double quotes (") to indicate an literal double quote character --%>
<c:setVariable var="var" select='   """ABC"""   '/>

<%-- using \" indicate to the tag attribute parser a literal double quote character.
  -- The XPath parser then needs no escaping --%>
<c:setVariable var="var" select="   '\"ABC\"'   "/>


In older JET versions, you have to resort to a bit of Java code to define variables containing the quote strings:

context.setVariable("dquote", "\""); // $dquote = a double quote
context.setVariable("squote", "'"); // $squote = a single quote
<c:setVariable var="var" select="concat($squote,'ABC',$squote)"/>
<c:setVariable var="var" select="concat($dquote,'ABC',$dquote)"/>