1. A computer-implemented method of editing elements of a first document based on elements of a second document, said elements of said first document having a template structure, each said template comprising at least one match condition, said match condition being an expression in said template that describes a subset of nodes that are matched in a tree structure, said second document containing a tree structure to which said matching is applicable, comprising: comparing a first selected fragment of an element from said first document with a second selected fragment of an element from said second document to determine if a match condition exists that describes the relation between templates in said first document, said match condition matching said first selected fragment and said second selected fragment; upon said match condition existing, receiving a predefined editing operation from a user; and performing the predefined editing operation by modifying the template structure of the elements of the first document, wherein the performing comprises: responsive to receiving a copy operation from the user, determining if the first selected fragment is a template rule with a match attribute; if the first selected fragment is a template rule with a match attribute, storing in a cut buffer a apply-templates rule with a select attribute and an origin match condition describing the second selected fragment; if the first selected fragment is not a template rule with a match attribute, storing in a cut buffer a copy of the first selected fragment and an origin match condition describing the second selected fragment.