Merging Documents with Unlike Schema
Problem
You have two or more dissimilar documents, and you would like to merge them into a single document.
Solution
The process of merging dissimilar data can vary from application to application. Therefore, this chapter cannot present a single generic solution. Instead, it anticipates common ways for two dissimilar documents to be brought together and provides solutions for each case.
Incorporate one document as a subpart of a parent document
Incorporating a document
as a subpart is the most trivial interpretation of this type of
merge. The basic idea is to use xsl:copy-of
to copy
one document or document part into the appropriate part of a second
document. The following example merges two documents into a container
document that uses element names in the container as indications of
what files to merge:
<MyNoteBook> <friends> </friends> <coworkers> </coworkers> <projects> <project>Replalce mapML with XSLT engine using Xalan C++</project> <project>Figure out the meaning of life.</project> <project>Figure out where the dryer is hinding all those missing socks</project> </projects> </MyNoteBook> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:import href="copy.xslt"/> <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/> <xsl:strip-space elements="*"/> <xsl:template match="friends | coworkers"> <xsl:copy> <xsl:variable name="file" select="concat(local-name( ),'.xml')"/> <xsl:copy-of select="document($file)/*/*"/> ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access