Difference between revisions of "M2T-JET-FAQ/How to I escape JET special characters?"

From Eclipsepedia

Jump to: navigation, search
(New page: 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...)
 
Line 11: Line 11:
 
<pre><some text></pre>
 
<pre><some text></pre>
  
== Comment lead-in and closing characters: <%-- and --%>
+
== 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 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:
Line 21: Line 21:
 
<pre><%-- this is not a JET comment --%></pre>
 
<pre><%-- this is not a JET comment --%></pre>
  
== Directive lead-in: <%@
+
== Directive lead-in: <%@ ==
  
 
The JET directive lead-in can be escaped by placing a backslash (\) before the % sign:
 
The JET directive lead-in can be escaped by placing a backslash (\) before the % sign:

Revision as of 09:37, 15 October 2012

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:

Contents

Tag lead-in characters: < and </

To escape a < characters, place a backslash (\) in front of it. Example:

JET template text:

\<some text>

Template output:

<some text>

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}