Example: Generating HTML pages from an XML document

This example uses features which are only available in the latest interim version of Epsilon.
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:

  • go to the SVN repository
  • navigate to trunk/examples
  • check out the org.eclipse.epsilon.examples.egl.library project

Once you have checked out/imported the code, to run the example you need to go through the following steps:

  1. register any .ecore metamodels in the org.eclipse.epsilon.examples.egl.library project
  2. right click the .launch file in the org.eclipse.epsilon.examples.egl.library project
  3. select Run as... and click the first item in the menu that pops up

What's this?

In this example, we use the plain XML driver of Epsilon in the context of an EGL model-to-text transformation.

What are .emf files?

.emf files are Ecore metamodels expressed using the Emfatic textual syntax.

More examples...

Epsilon Object Language
Epsilon Transformation Language
Epsilon Generation Language
Epsilon Validation Language
Epsilon Merging Language
Epsilon Flock
Combining the Epsilon Languages
EuGENia
EUnit

Even more examples...

More examples are available in the examples folder of the SVN repository.