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

Run an application as Administrator with predefined username and password

c# windows file-io permissions administrator

In my application I have some Save methods that store data on user's hard disk. How could it be possible to prevent the user from getting access, change or delete that files as soon as the applicat...

how to refresh the linear layout view after deleting an element

refresh android-linearlayout

I have a simple app, in one activity I take name and date of birth. I store it in the database. and in the main activity I have linearlayout which will show all the names.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.