Tuesday, 27 August 2013

XSLT Data Merge

XSLT Data Merge

I have a very basic knowledge of XSLT and I am currently trying to achieve
something which I am still trying to figure out if its possible.
Can be XSLT 1.0 or 2.0
Basically this is the structure of my XML
<?xml version="1.0" encoding="windows-1252"?>
<Root>
<DataPage>
<Record>
<TEMP>xxx</TEMP>
<DEBITNO>6250281</DEBITNO>
<DOSSIERNUMMERINT>2012365</DOSSIERNUMMERINT>
<ID>0123456789Z60</ID>
<DATE>31/01/2013</DATE>
<YEAR>2006</YEAR>
<DESC>Test Item 1</DESC>
<AMOUNT> 38170.0000000</AMOUNT>
<HEAD>123</HEAD>
</Record>
</DataPage>
<DataPage>
<Record>
<TEMP>xxx</TEMP>
<DEBITNO>6250281</DEBITNO>
<DOSSIERNUMMERINT>2012365</DOSSIERNUMMERINT>
<ID>0123456789Z70</ID>
<DATE>22/02/2013</DATE>
<YEAR>2006</YEAR>
<DESC>Test Item 2</DESC>
<AMOUNT> 14410.0000000</AMOUNT>
<HEAD>123</HEAD>
</Record>
</DataPage>
<DataPage>
<Record>
<TEMP>xxx</TEMP>
<DEBITNO>3849322</DEBITNO>
<DOSSIERNUMMERINT>20132394</DOSSIERNUMMERINT>
<ID>34958701223Z20</ID>
<DATE>06/01/2013</DATE>
<YEAR>2006</YEAR>
<DESC>Test Item 1</DESC>
<AMOUNT> 33811.0000000</AMOUNT>
<HEAD>567</HEAD>
</Record>
</DataPage>
</Root>
I would like this the output the following
<?xml version="1.0" encoding="windows-1252"?>
<Root>
<DataPage>
<Record>
<TEMP>xxx</TEMP>
<DEBITNO>6250281</DEBITNO>
<DOSSIERNUMMERINT>2012365</DOSSIERNUMMERINT>
<Line>
<ID>0123456789Z60</ID>
<DATE>31/01/2013</DATE>
<YEAR>2006</YEAR>
<DESC>Test Item 1</DESC>
<AMOUNT> 38170.0000000</AMOUNT>
</Line>
<Line>
<ID>0123456789Z70</ID>
<DATE>22/02/2013</DATE>
<YEAR>2006</YEAR>
<DESC>Test Item 2</DESC>
<AMOUNT> 14410.0000000</AMOUNT>
</Line>
<HEAD>123</HEAD>
</Record>
</DataPage>
<DataPage>
<Record>
<TEMP>xxx</TEMP>
<DEBITNO>3849322</DEBITNO>
<DOSSIERNUMMERINT>20132394</DOSSIERNUMMERINT>
<Line>
<ID>34958701223Z20</ID>
<DATE>06/01/2013</DATE>
<YEAR>2006</YEAR>
<DESC>Test Item 1</DESC>
<AMOUNT> 33811.0000000</AMOUNT>
</Line>
<HEAD>567</HEAD>
</Record>
</DataPage>
</Root>
So the logic would be to merge all records with the same DEBITNO.
The rules for the merge is everything other than ID, Date, Year, DESC and
AMOUNT can be taken from the 1st appearance
ID, Date, Year, DESC and AMOUNT needs to be placed into a tag, so if there
are 2 records with the same DEBITNO there will be 2 line items, if there
are 5 records with the same DEBITNO the resulting record will have 5 line
items.
I hope that makes sense.
Is something like this possible?
Regards,

No comments:

Post a Comment