rule Book2Page
transform book : t_book {
// We only want to generate pages
// for books that have their public
// attribute set to true
guard : book.b_public
parameters {
// These parameters will be made available
// to the invoked template as variables
var params : new Map;
params.put("index", t_book.all.indexOf(book) + 1);
return params;
}
// The EGL template to be invoked
template : "book2page.egl"
// Output file
target : "gen/" + book.e_id.text + ".html"
}
rule Library2Page
transform library : t_library {
template : "library2page.egl"
target : "gen/index.html"
}
[*- Heading *]
<h1>Book [%=index%]: [%=book.a_title%]</h1>
[*- List of authors *]
<h2>Authors</h2>
<ul>
[%for (author in book.c_author) { %]
<li>[%=author.text%]
[%}%]
</ul>
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<library>
<book title="EMF Eclipse Modeling Framework" pages="744" public="true">
<id>EMFBook</id>
<author>Dave Steinberg</author>
<author>Frank Budinsky</author>
<author>Marcelo Paternostro</author>
<author>Ed Merks</author>
<published>2009</published>
</book>
<book title="Eclipse Modeling Project: A Domain-Specific Language (DSL) Toolkit"
pages="736" public="true">
<id>EMPBook</id>
<author>Richard Gronback</author>
<published>2009</published>
</book>
<book title="Official Eclipse 3.0 FAQs" pages="432" public="false">
<id>Eclipse3FAQs</id>
<author>John Arthorne</author>
<author>Chris Laffra</author>
<published>2004</published>
</book>
</library>
<h1>Book 1: EMF Eclipse Modeling Framework</h1> <h2>Authors</h2> <ul> <li>Dave Steinberg <li>Frank Budinsky <li>Marcelo Paternostro <li>Ed Merks </ul>
Check out the code from the SVN:
Once you have checked out/imported the code, to run the example you need to go through the following steps:
In this example, we use the plain XML driver of Epsilon in the context of an EGL model-to-text transformation.
.emf files are Ecore metamodels expressed using the Emfatic textual syntax.
More examples are available in the examples folder of the SVN repository.