1. A computer-implemented method of transforming a document, including: using a processor, responding to an element start-event in an event data stream by searching for a named template that matches the element start-event, upon finding a matching named template, activating the named template, and upon not finding the matching named template, treating an element between the element start-event and an element end-event of the event data stream as content of a parent element; and responding to the element end-event paired to the element start-event, using the activated named template, including: responsive to instructions in the named template, outputting at least some of literal text, input events received in the event data stream between the element start-event and the element end-event, or variables that store values from content, attributes or labels of an element; and clearing at least the input events received in the event data stream between the element start-event and the element end-event.