Abbey Workshop | ||||||||||
This tip demonstrates how to include several different XML documents using XSLT. This is done using the document function of XSLT. In this example, we want to combine three files that contain a name an e-mail address into one output document. Here is an example of one of the input files.
Download source for: mail1.xml
To include this file and the other two, we need to include references to the files in an XML file that summarizes all the files to be included. Our stylesheet will run against this file.
Download source for: maillist.xml
Finally, we need to write an XSLT stylesheet which reads the maillist.xml file and incorporates mail1.xml, mail2.xml, and mail3.xml.
Download source for: mergedocs.xsl
The xsl:foreach tag loops on each tag containing one of the file names (/mail_list/file in this case). The xsl:apply-templates tag does a select on each file using this statement: document(@name)/entry. This statement opens each file and selects the the entry element from the document root for each file. Any XSLT templates are applied to entry and any of its subelements.
Here is what the output from the program looks like.
Name: John Doe EMail Address: jdoe@example1.com Name: Jane Smith EMail Address: jane@example2.com Name: Jill Jones EMail Address: jill@example3.com
Copyright © Abbey Workshop 2006