Example: Generating HTML pages from an XML document

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 *]
[%for (author in book.c_author) { %]
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
  <book title="EMF Eclipse Modeling Framework" pages="744" public="true">
    <author>Dave Steinberg</author>
    <author>Frank Budinsky</author>
    <author>Marcelo Paternostro</author>
    <author>Ed Merks</author>
  <book title="Eclipse Modeling Project: A Domain-Specific Language (DSL) Toolkit" 
    pages="736" public="true">
    <author>Richard Gronback</author>
  <book title="Official Eclipse 3.0 FAQs" pages="432" public="false">
    <author>John Arthorne</author>
    <author>Chris Laffra</author>
<h1>Book 1: EMF Eclipse Modeling Framework</h1>

  <li>Dave Steinberg
  <li>Frank Budinsky
  <li>Marcelo Paternostro
  <li>Ed Merks
* Copyright (c) 2008 The University of York.
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
* SPDX-License-Identifier: EPL-2.0
package org.eclipse.epsilon.examples.egl.library;

import java.io.File;

import org.eclipse.epsilon.egl.EglFileGeneratingTemplateFactory;
import org.eclipse.epsilon.egl.EgxModule;
import org.eclipse.epsilon.emc.plainxml.PlainXmlModel;

public class App {
  public static void main(String[] args) throws Exception {
    // Parse main.egx
    EgxModule module = new EgxModule(new EglFileGeneratingTemplateFactory());
    module.parse(new File("main.egx").getAbsoluteFile());
    if (!module.getParseProblems().isEmpty()) {
      System.out.println("Syntax errors found. Exiting.");
    // Load the XML document
    PlainXmlModel model = new PlainXmlModel();
    model.setFile(new File("library.xml"));
    // Make the document visible to the EGX program
    // ... and execute

Clone Epsilon's Git repository and then:

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
Epsilon Model Generation Language
Epsilon Pattern Language
Combining the Epsilon Languages

Even more examples...

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