Jump to content

Combining XML files into one during transformation


scopley

Recommended Posts

I am looking for a way to combine over 100 xml files located in the same directory into 1 xml file during transformation. I know that I can use variables to acess the data from the different files but to list each file individually is cumberson and they will be subject to change. Is there a .xml wildcard that will pull all the .xml files within a specific directory?Here is the code:<?xml version="1.0" encoding="UTF-8"?><xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format"> <xsl:variable name="allxml" select="document('C:\TEST\mp200090.xml') /mpc/idinfo/cardno | document('C:\TEST\ma500010.xml') /mpc/idinfo/cardno | document('C:\TEST\mq000010.xml') /mpc/idinfo/cardno"/> <xsl:template match="/"> <xsl:for-each select="$allxml"> <mpcnum> <xsl:value-of select="."/> </mpcnum> </xsl:for-each> </xsl:template></xsl:stylesheet>Thanks in advance for your help.

Link to comment
Share on other sites

I must say the XSLT you have is probably invalid to begin with and totally off the table.There are two approaches you can take, but both requre that you generate a list of the XML files with S3L at your disposal. Ideally, generate a list of them in a new XML file with a structure like this:

<l><f>ma500010.xml</f><f>mq000010.xml</f>...</l>

where the names of the elements can be whatever you want, and apply the following XSLT over that file:

<?xml version="1.0" encoding="UTF-8"?><xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"><xsl:template match="/*"><!-- The "n" element is actually the new element that will be the root element of the new XML file. All root elements of all other XML files will be it's childs. You can safely rename "n" to whatever you want to. --><n><xsl:apply-templates select="*"/></n></xsl:template><xsl:template match="*"><xsl:copy-of select="document(.)/*"/></xsl:template></xsl:stylesheet>

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...