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 matching an element name for the element start-event to a template name and activating a matching-name template and, lacking a match, by treating the element between the element start-event and an element end-event as content of a parent element; responding to an element end-event paired to the start-event using the template that was activated, including: responsive to instructions in the matching-name template, outputting at least some of literal text or input events received in the event data stream between the start-event and the end-event; clearing the input events received in the event data stream between the start-event and the end-event; and deactivating the matching named template.