Abbey Workshop

XSLT: Reading Multiple Files with the document() Function

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.

mail1.xml

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.

maillist.xml

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.

mergedocs.xsl

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
		
Google
  Web abbeyworkshop.com   

Copyright © Abbey Workshop 2006

Music Only Search
The Black MP3 Album
The MP3 Album Lyrics
Wprld Music Plus
Mp3 Songs Blog
Music Search Store
First Music Search
Mega MP3 Blog
E MP3 BLog
My MP3 Diary
Fast MP3 Finder
My Blog MP3
Mp3 Songs Mart
My MP3 Songs Album
Top Music Group
Mp3 Tune Records
Song Album Guide
Music DataDite
MP3 Buying Guide
Top MP3 Downloads
MP3 Tune Festival
FAST MP3 Downloads
MP3 Mart Online
Upper MP3
Premium MP3 Site
Music Data online
Fine MP3 Audio
Cheap Music Albums
Fine mp3 downloads
World MP3 Music Records
Mp3 Music Data Direct
The Fine Mp3
MP3 Files World
Home Music Store
DatMP3
Fat MP3 Audio
MP3 ZigZag
MP3 Songs Direct
MP3 Tune World
E MP3 Log
Boom MP3 Music
Speedy MP3
Top 20 MP3 music
Deep MP3 World
Deep MP3 Download
Best-20 MP3
Top Twenty MP3
Deep MP3
Big MP3 Guide
Deep MP3 Audio
Mp3 R.O.B.
MP3-Pop Online
Greate-20-MP3
MP3 Appear
3T-MP3