how to transform indidual xml messages into common XML document with XSLT

I have the below xml messages created by Tibco

<?xml version="1.0" encoding="UTF-8"?>
<SalesInData>
    <COMPANYID>AIN2003</COMPANYID>
    <ENDDATE>20120825</ENDDATE>
    <FILENAME>2-SG4_2244_20120815.xml</FILENAME>
    <SalesInRecord>
        <ROW_NUM>7</ROW_NUM>
        <BUY_QTY>5</BUY_QTY>
        <HP_PRODUCT_ID>Apj45685</HP_PRODUCT_ID>
        <LOCATION_ID/>
        <LOCATION_NAME>XYZ XY</LOCATION_NAME>
        <UNIT_BUY_PRICE>999999999</UNIT_BUY_PRICE>
    </SalesInRecord>
    <STARTDATE>20120819</STARTDATE>
    <SUBMITDATE>20120827</SUBMITDATE>
</SalesInData>
<?xml version="1.0" encoding="UTF-8"?>
<SalesInData>
    <COMPANYID>AIN2003</COMPANYID>
    <ENDDATE>20120825</ENDDATE>
    <FILENAME>2-SG4_2244_20120815.xml</FILENAME>
    <SalesInRecord>
        <ROW_NUM>1</ROW_NUM>
        <BUY_QTY>5</BUY_QTY>
        <HP_PRODUCT_ID>Apj45678</HP_PRODUCT_ID>
        <LOCATION_ID>2-PQL-3401</LOCATION_ID>
        <LOCATION_NAME>XYZ el</LOCATION_NAME>
        <UNIT_BUY_PRICE>999999999</UNIT_BUY_PRICE>
    </SalesInRecord>
    <STARTDATE>20120819</STARTDATE>
    <SUBMITDATE>20120827</SUBMITDATE>
</SalesInData>
<?xml version="1.0" encoding="UTF-8"?>
<SalesInData>
    <COMPANYID>AIN2003</COMPANYID>
    <ENDDATE>20120825</ENDDATE>
    <FILENAME>2-SG4_2244_20120815.xml</FILENAME>
    <SalesInRecord>
        <ROW_NUM>1</ROW_NUM>
        <BUY_QTY>5</BUY_QTY>
        <HP_PRODUCT_ID>Apj45678</HP_PRODUCT_ID>
        <LOCATION_ID>2-PQL-3401</LOCATION_ID>
        <LOCATION_NAME>XYZ el</LOCATION_NAME>
        <UNIT_BUY_PRICE>999999999</UNIT_BUY_PRICE>
    </SalesInRecord>
    <STARTDATE>20120819</STARTDATE>
    <SUBMITDATE>20120827</SUBMITDATE>
</SalesInData>

but expected output will be:

<?xml version="1.0" encoding="UTF-8"?>
<SalesInData>
    <COMPANYID>AIN2003</COMPANYID>
    <ENDDATE>20120825</ENDDATE>
    <FILENAME>2-SG4_2244_20120815.xml</FILENAME>
    <SalesInRecord>
        <ROW_NUM>7</ROW_NUM>
        <BUY_QTY>5</BUY_QTY>
        <HP_PRODUCT_ID>Apj45685</HP_PRODUCT_ID>
        <LOCATION_ID/>
        <LOCATION_NAME>XYZ XY</LOCATION_NAME>
        <UNIT_BUY_PRICE>999999999</UNIT_BUY_PRICE>
        <GOODS_RECIVED_DATE/>
    </SalesInRecord>
    <SalesInRecord>
        <ROW_NUM>1</ROW_NUM>
        <BUY_QTY>5</BUY_QTY>
        <HP_PRODUCT_ID>Apj45678</HP_PRODUCT_ID>
        <LOCATION_ID>2-PQL-3401</LOCATION_ID>
        <LOCATION_NAME>XYZ el</LOCATION_NAME>
        <UNIT_BUY_PRICE>999999999</UNIT_BUY_PRICE>
        <GOODS_RECIVED_DATE/>
    </SalesInRecord>
    <SalesInRecord>
        <ROW_NUM>1</ROW_NUM>
        <BUY_QTY>5</BUY_QTY>
        <HP_PRODUCT_ID>Apj45678</HP_PRODUCT_ID>
        <LOCATION_ID>2-PQL-3401</LOCATION_ID>
        <LOCATION_NAME>XYZ el</LOCATION_NAME>
        <UNIT_BUY_PRICE>999999999</UNIT_BUY_PRICE>
        <GOODS_RECIVED_DATE/>
    </SalesInRecord>
    <STARTDATE>20120819</STARTDATE>
    <SUBMITDATE>20120827</SUBMITDATE>
</SalesInData>

but i want to transform this individual xml records which are created in tibco into single xml document with XSLT as shown above. please provide the code that can perform the task. there are some other elements which can be null.

Answers


Your input file is no well formed XML so no xslt processor will work with it. The only way I see is to produce a xml file at first and a simple xsl processing in the following step.

  1. Remove the xml intros '<?xml version="1.0" encoding="UTF-8"?>' for instance with sed or another tool
  2. Put the result in your own root element
  3. Do the desired xslt tranformation

#simple bash examplesed -e 's/<?xml version="1.0" encoding="UTF-8"?>//g' YOUR_INPUT > temp.file echo '<?xml version="1.0" encoding="UTF-8"?>' > temp2.file echo "<MyStart>" >> temp2.file cat temp.file >> temp2.file echo "</MyStart>" >> temp2.file xsltproc YOUR_STYLESHEET temp2.file > YOUR_RESULT


Need Your Help

Restrict creation of children forms using generics in C#

c# winforms generics generic-programming

After testing for a bit, I came up with the following solution to avoid (from the MdiParent Form) the creation of more than one instance of children forms.

throwing an exception in objective-c/cocoa

objective-c cocoa

What's the best way to throw an exception in objective-c/cocoa?

Redeclaration of a variable in a for-loop in C++

c++ for-loop declaration

When trying to compile the following (simplified) code for multiple platforms, I found that it was failing on some, namely IBM's xlC_r. Further investigation has found that it also fails on comeau...