1

I want to merge multiple xml files into single xml files while sending to destination folder in BizTalk.Help me in transforming multiple xml files to single xml file using xslt or other easier way.Please note All the input files holds same namespace input 1

<?xml version="1.0" encoding="utf-8"?>
<ns0:AssetStatusResF xmlns:ns0="http://uCustoms/IL/MC/AssetStockResF/v1.0"
    xmlns:nsHeader="http://uCustoms/Common/Header/v1.0">
    <Body>
        <parameter>
            <AssetID>KK/KDRM115/I/06/15</AssetID>
            <StatusCode>D</StatusCode>
            <Status>Penghapusan</Status>
            <PlacementLocationCode>160101/BGN/HU/09/B12</PlacementLocationCode>
            <PlacementLocation>BILIK TIMBALAN PENGARAH (PERJAWATAN)</PlacementLocation>
            <PlacementDate>12/7/2008 12:00:00 AM</PlacementDate>
            <DisposedDate/>
        </parameter>
    </Body>
</ns0:AssetStatusResF>

input2

    <?xml version="1.0" encoding="utf-8"?>
<ns0:AssetStatusResF xmlns:ns0="http://uCustoms/IL/MC/AssetStockResF/v1.0"
    xmlns:nsHeader="http://uCustoms/Common/Header/v1.0">
    <Body>
        <parameter>
            <AssetID>KK/KDRM115/H/06/4</AssetID>
            <StatusCode>A</StatusCode>
            <Status>Sedang Digunakan</Status>
            <PlacementLocationCode>160101/BGN/HS/09/B07</PlacementLocationCode>
            <PlacementLocation>BILIK PENASIHAT</PlacementLocation>
            <PlacementDate>12/26/2017 12:00:00 AM</PlacementDate>
            <DisposedDate/>
        </parameter>
    </Body>
</ns0:AssetStatusResF>

input3,4....... goes on

output

    <?xml version="1.0" encoding="utf-8"?>
<ns0:AssetStatusResF xmlns:ns0="http://uCustoms/IL/MC/AssetStockResF/v1.0"
    xmlns:nsHeader="http://uCustoms/Common/Header/v1.0">
    <Body>
        <parameter>
            <AssetID>KK/KDRM115/H/06/4</AssetID>
            <StatusCode>A</StatusCode>
            <Status>Sedang Digunakan</Status>
            <PlacementLocationCode>160101/BGN/HS/09/B07</PlacementLocationCode>
            <PlacementLocation>BILIK PENASIHAT</PlacementLocation>
            <PlacementDate>12/26/2017 12:00:00 AM</PlacementDate>
            <DisposedDate/>
        </parameter>
        <parameter>
            <AssetID>KK/KDRM115/I/06/15</AssetID>
            <StatusCode>D</StatusCode>
            <Status>Penghapusan</Status>
            <PlacementLocationCode>160101/BGN/HU/09/B12</PlacementLocationCode>
            <PlacementLocation>BILIK TIMBALAN PENGARAH (PERJAWATAN)</PlacementLocation>
            <PlacementDate>12/7/2008 12:00:00 AM</PlacementDate>
            <DisposedDate/>
        </parameter>
    </Body>
</ns0:AssetStatusResF>
Michael Kay
  • 156,231
  • 11
  • 92
  • 164
Chitra
  • 21
  • 1
  • 8

2 Answers2

1

Here's one way.

Create a document that lists the documents you want to combine in collection.xml:

<collection>
  <doc href="input1.xml"/>
  <doc href="input2.xml"/>
  <doc href="input3.xml"/>
</collection>

Then do an XSLT transformation using collection.xml as the source document and the following stylesheet:

<xsl:transform version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="collection">
  <ns0:AssetStatusResF xmlns:ns0="http://uCustoms/IL/MC/AssetStockResF/v1.0">
    <Body>
      <xsl:copy-of select="document(doc/@href)/*/Body/parameter"/>
    </Body>
  </ns0:AssetStatusResF>
</xsl:template>

</xsl:transform>

That will work with XSLT 1.0. If you move to XSLT 2.0 there are more flexible ways of supplying the input, for example you can use the collection() function to access all the files in a directory.

Michael Kay
  • 156,231
  • 11
  • 92
  • 164
  • Thanks Michael.Since i am new to xslt could you please help me in implementing collection function in the above xslt code to access the files in directory – Chitra Jun 08 '16 at 07:36
0

If you are using XSLT 2.0, a couple of alternatives are available. Firstly, you could define the list of documents as a stylesheet parameter, passed in as a sequence of strings:

<xsl:param name="docs" as="xs:string*"/>

<xsl:template match="collection">
  <ns0:AssetStatusResF xmlns:ns0="http://uCustoms/IL/MC/AssetStockResF/v1.0">
    <Body>
      <xsl:copy-of select="document($docs)/*/Body/parameter"/>
    </Body>
  </ns0:AssetStatusResF>
</xsl:template>

Or you could define the documents as a collection. Saxon and some other processors map a collection URI to a filestore directory. In Saxon you could do:

    <xsl:template name="main">
      <ns0:AssetStatusResF xmlns:ns0="http://uCustoms/IL/MC/AssetStockResF/v1.0">
        <Body>
          <xsl:copy-of select="collection('file:///c:/mydocs?select=*.xml')/*/Body/parameter"/>
        </Body>
      </ns0:AssetStatusResF>
    </xsl:template>

What works best though, depends on how you decide which input documents to process, and you haven't really explained that.

Michael Kay
  • 156,231
  • 11
  • 92
  • 164
  • The input file which i am using is an xml document – Chitra Jun 09 '16 at 04:20
  • 00000003-0003-0003-0003-000000000003 2016-12-31T12:22:30Synchronous falseMCTOIL AssetStockReqRequest
    KK/KDRM115/I/06/2
    – Chitra Jun 09 '16 at 04:25
  • Please take the trouble to indent your XML before posting. Any XML Editor will do this for you. – Michael Kay Jun 09 '16 at 07:11
  • Since the comment tab accept only limited characters, i have provided the xml in such a way.Sorry for the inconvenience. – Chitra Jun 09 '16 at 07:24
  • Since the new information should have been part of the question in the first place, the appropriate thing to do is to edit your question to add the extra information. – Michael Kay Jun 09 '16 at 09:47