Composing document-to-document transformation

The following listing provides pseudo-code of a generic function get-local-instantiation, which implements local instantiation: consuming a model node and the source context of a parent instance node, returning the instances of the model node which are child node of the given parent node. Note the representation of the mapping functions as properties of the model node, using dot notation, for instance:


This reflects our intent to provide the primitive operations as metadata of the model node.

Figure 1. Pseudo code of get-local-instantiation, a function implementing local instantiation. An auxiliary function new-node is assumed to be available, which constructs a node, given the node kind, the node name and the node contents.

get-local-instantiation($location       as location, 
                        $parent-context as node()*) 
as node()* {
   $propagated-context = $location.context-propagator
                                    (parent-context = $parent-context)
   $context-array      = $location.context-distributor
                                (propagated-context = $propagated-context)
   for $context in $context-array:
      node-for-context(location = $location, 
                        context = $context)

node-for-context($location as location, 
                 $context  as node()*) 
as node() {
   $content =
      if $ 
         $location.context-atomizer(context = $context)
         for $child-location in $location.child-locations:
            get-local-instantiation(      location = $child-location, 
                                    parent-context = $context)
      new-node(   kind = $location.node-kind, 
                  name = $, 
               content = $content)

Definition of a function get-local-instantiation amounts to a complete definition of document-to-document transformation: the transformation is achieved by applying get-local-instantiation to the root location of the target document. In this initial invocation, the input value of a parent context is axiomatically set to the root node of the source document.

While the primitive operations can be regarded as properties of the model nodes, the metadata expected by a code generator need not necessarily represent them one-to-one, as long as they can be derived from the metadata. The following section introduces a metadata model which is used by an actual code generator described later.