This lesson further examines the JET input model, how to use XPath
expressions to traverse the input model, and how JET actions relate to the
input model.
JET input model The input models that you create by authoring
JET transformations have the following characteristics:
- The model is hierarchical and has a single root element
- Each element type in the model might contain attributes that have string
values
- Element containment always specifies a cardinality of zero or greater
than zero
The capabilities of the model are deliberately restrictive to make
it easier to create model-to-text transformations quickly without requiring
the user to have a deep understanding of metamodel design.
Model
processing by JET transformations and invoking actions
The JET Authoring
editor generates code to process the input model. This code is located in
the main.jet template, and has the following characteristics:
- The generated code performs a depth-first traversal of the model.
- The code processes the model twice: The first iteration evaluates derived
attribute expressions. The second iteration invokes JET actions that create
projects, folders, and files. The JET actions that create files are called
JET File actions, and they invoke JET templates.
- During processing, each model element is assigned to an XPath variable.
The name of this variable is defined in the Properties view for the element
type that is visible in the editor area. By default, the name of the variable
is the same as the name of the model element. You can distinguish the variable
from the element name because XPath variables are always prefixed by a dollar
sign ($) in an XPath expression.
- During the processing of an element, the first iteration calculates derived
attributes; the second iteration runs JET actions, and processes the child
model elements.
- The XPath variables that are associated with the current element and all
its parent elements are available during derived attribute calculation and
JET action invocation. Therefore, any derived attribute calculation, JET action,
or JET template that a JET file action invokes might reference the currently
processed element or any of its parent elements by using an XPath variable.
As an example, consider the model in this module. The following image
shows the contents of the "Input schema and output actions" pane.
The
action named Create File: letter.html and the associated JET template (templates/letter.html.jet)
are invoked each time a mailing element is encountered under the root element.
Both the action and the template have access to two XPath variables: $mailing
and $root. Action parameters and text replacements can use any attributes
that belong to the element types called mailing and root.
XPath expressions
and renaming model elements
The XPath expressions that the JET authoring
functionality creates always have the form $variable/@attribute. The JET authoring
functionality refactors such expressions if the variable name or the element
type is renamed. However, this refactoring does not extend to JET templates.
That is, renaming a variable or element type in the JET Authoring editor breaks
any XPath expressions in JET templates that use the old variable name.