As a template system, JET2 is function similar to writing JSP pages. It supports tag libraries and Java™ snippets where needed. JET2 can also directly use an EMF model as its input, if the templates have been written to the specification for that particular model.
http://www.ibm.com/developerworks/opensource/library/os-ecl-jet/
<?xml version="1.0" encoding="UTF-8"?>
<dataAccess:Employee xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:dataAccess="http:///dataAccess.ecore" name="Bob Smith" address="123 Main St" employeeNumber="12345">
<customers name="Sam Brown" address="55 Bank St">
<orders orderNumber="101" date="2005-12-15T00:00:00.000-0500" quantity="25"/>
<orders orderNumber="13" date="2005-11-15T00:00:00.000-0500" quantity="55"/>
</customers>
<customers name="Tim Safari" address="18 Elephant Rd">
<orders orderNumber="77" date="2005-11-20T00:00:00.000-0500" quantity="3"/>
</customers>
</dataAccess:Employee>
<%@taglib prefix="ws" id="org.eclipse.emf.jet2.workspaceTags" %>
<%-- run a template that lists employees and creates a file list.txt --%>
<ws:file template="templates/listEmployees.jet" path="list.txt"/>
<%@taglib prefix="c" id="org.eclipse.emf.jet2.controlTags" %>
<%-- /selects the document root, which in this case is the emf Resource object --%>
<%-- /selects the contents of the Resource.getContents() --%>
<c:iterate select="/contents" var="employee">
Employee: <c:get select="$employee/@name"/> (<c:get select="$employee/@employeeNumber"/>), <c:get select="$employee/@address"/>
<c:iterate select="$employee/customers" var="customer">
Customer: <c:get select="$customer/@name"/>, <c:get select="$customer/@address"/>
<c:iterate select="$customer/orders" var="order">
Order: <c:get select="$order/@orderNumber"/>, <c:get select="$order/@date"/>, qty: <c:get select="$order/@quantity"/>
</c:iterate>
</c:iterate>
</c:iterate>
Orders for 'Sam Brown'
<c:iterate select="/contents/customers [@name='Sam Brown']/orders" var="order">
Order: <c:get select="$order/@orderNumber"/>, <c:get select="$order/@date"/>, qty: <c:get select="$order/@quantity"/>
</c:iterate>
Evaluates an XPath expression (getting a result set of some sort), and processes the tag contents time for each element in the result set.
Evaluates an XPath expression, converts the result to a string, and writes it to the template output.
When XPath expressions are evaluated, the initial / is mapped to the EMF Resource object. The root element of the resource is accessed by referencing the contents child (/contents). This is equivalent to calling Resource.getContents(). For example, the tag <c:iterate select="/contents" var="employee"> iterates over the result set of Resource.getContents(). In each iteration, the current element in the result set is pointed to by the employee variable.
After the initial Resource object, the tag <c:iterate select="$employee/customers" var="customer">
<c:get select="$employee/@name"/>
This
returns the value of the name attribute on Employee
(Employee.getName()).<c:iterate select="/contents/customers [@name='Sam Brown']/orders" var="order">
This
code finds customers whose name attribute equals Sam
Brown, finds their orders, and iterates over them. Employee: Bob Smith (12345), 123 Main St
Customer: Sam Brown, 55 Bank St
Order: 101, Thu Dec 15 00:00:00 EST 2005, qty: 25
Order: 13, Tue Nov 15 00:00:00 EST 2005, qty: 55
Customer: Tim Safari, 18 Elephant Rd
Order: 77, Sun Nov 20 00:00:00 EST 2005, qty: 3
Orders for 'Sam Brown'
Order: 101, Thu Dec 15 00:00:00 EST 2005, qty: 25
Order: 13, Tue Nov 15 00:00:00 EST 2005, qty: 55
For additional information, see JET Tutorial.