Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

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

< M2T-JET-FAQ
Revision as of 11:43, 13 March 2009 by Pelder.ca.ibm.com (Talk | contribs) (New page: == Question == 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). == Answer == As of JET 0.9, y...)

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

Question

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).

Answer

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\"'   "/>

</pre>

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)"/>

Copyright © Eclipse Foundation, Inc. All Rights Reserved.