Skip to main content
Jump to: navigation, search

M2T-JET-FAQ/How to I escape JET special characters?

Revision as of 08:51, 31 July 2013 by (Talk | contribs) (Tag lead-in characters: < and </)

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

JET recognizes a number of characters is lead-ins to tags, comments, directives and embedded XPath expressions. If you need to include these characters in your template output, you need to escape them. Different techniques are required for different types of characters:

Tag lead-in characters: < and </

Your choices are the following alternatives:

If you are working with JET 1.0 or later, you can escape the leading < character with the compact XPath expression ${'<'} :


See Compact alternative to c:get tag, for more details. Alternatively, you can use the taglib directive to change the namespace of your tags.

You can change the namespace of the tags you emit:

<%-- Your template uses c:, but emits cc: for control tags --%>
<%-- emit tag so that the output tags are bound to cc. This needs to be escaped --%>
<\%@taglib prefix="cc" id="org.eclipse.jet.controlTags" %>
<c:if test="someCondition">
   <cc:iterate select="...">...</cc:iterate>

Or, you can change the namespace of your template's tags:

<%-- Your template uses cc:, but emits c: for control tags --%>
<%-- Indicate that this templates uses cc prefix for control tags --%>
<%@taglib prefix="cc" id="org.eclipse.jet.controlTags" %>
<cc:if test="someCondition">
   <c:iterate select="...">...</c:iterate>

JET has used the latter technique since inception to generate new JET projects.

Comment lead-in and closing characters: <%-- and --%>

JET comment lead-in and closing characters can be escaped by placing a backslash (\) before the % sign on the lead-in and the > on the closing:

JET template text:

<\%-- this is not a JET comment --%\>

Template output:

<%-- this is not a JET comment --%>

Directive lead-in: <%@

The JET directive lead-in can be escaped by placing a backslash (\) before the % sign:

JET template text:

<\%@NOT a JET Directive%>

Template output:

<%@NOT a JET Directive%>

Embedded XPath expression lead-in: ${

The embedded XPath lead-in can be escaped by putting part or all of the lead-in into an enclosing embedded XPath expression that returns a string.

JET template text. Here ${'$'} is an embedded XPath expression ('$'), which returns a single character $:

The minimum needed: ${'$'}{someStaticText}

Template output:

The minimum needed: ${someStaticText}

JET template text. Here, an embedded XPath expression returns the entire string ${someStaticText}:

An alternative - quote the entire expression: ${'${someStaticText}'}

Template output:

An alternative - quote the entire expression: ${someStaticText}

Back to the top