The transformation is achieved by associating patterns with templates. A pattern is matched against elements in the source tree. A template is instantiated to create part of the result tree, which is separate from the source tree, and whose structure can be completely different from the structure of the source tree. In constructing the result tree, elements from the source tree can be filtered and reordered, and arbitrary structure can be added. When a template is instantiated, each instruction is executed and replaced by the result tree fragment that it creates.
Instructions can select and process descendant source elements.
Note that elements are only processed when they have been selected by the execution of an instruction. The result tree is constructed by finding the template rule for the root node and instantiating its template. When finding the applicable template rule, more than one template rule may have a pattern that matches a given element. However, only one template rule will be applied. A conflict resolution mechanism exists.