A target document (25) is generated by merging four source documents (2-5). There are three merge operations, an operation (10) for two source documents (2, 13), an operation (13) for an intermediate target document and a source document (4), and an operation (21) for a second intermediate target document and a final source document (5). In each merge operation one source document inherits from the other. An inheriting instruction is embedded within the inheriting document. Merging is performed by parsing a document (6, 8, 11, 20) into a hierarchical tree if it is not already in that form, and merging the trees. Matching nodes are identified and are combined or replaced according to a policy.