O'Reilly logo

XSLT Cookbook by Sal Mangano

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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)/*/*"/> ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required