XSL: Several XML files into one file

We have a lot of separate files and want to put them together into one.

Step 1: Create a list of all filenames as XML file

<files>
<file>file1.xml</file>
<file>file2.xml</file>
<file>file3.xml</file>
</files>

Step 2: Create an XSL transform

<xsl:template match="//files">
<Root>
<xsl:for-each select="file">
<xsl:copy-of select="document(.)"/>
</xsl:for-each>
</Root>
</xsl:template>

Note the use of “copy-of” – it will copy all the nodes and attributes from the source XML.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s