[xsl] Merge Similar data nodes using XSL

Subject: [xsl] Merge Similar data nodes using XSL
From: Sunder Rajan <arun_9033@xxxxxxxxx>
Date: Sun, 15 Feb 2009 23:02:37 -0800 (PST)
Hi All,

I have posted this after a bit of research and being new to XSLT.

There were similar clarifications in the past(FAQ) that helped me to move
however I would appreciate if any one can suggest me if I am heading in the
right direction.

1. Here is the XML sampple
<Contribution>
         <AccountID>100</AccountID>
         <AccountIDPub>173</AccountIDPub>
         <EmployeeSurname>XXXX</EmployeeSurname>
         <EmployeeFirstName>Sharon</EmployeeFirstName>
         <EmployeeDOB>07/12/1955</EmployeeDOB>
         <DateLastPaidTo>02/01/2009</DateLastPaidTo>
         <ContributionType>Comp Emp</ContributionType>
         <ContributionAmount>400.0</ContributionAmount>
      </Contribution>
<Contribution>
         <AccountID>100</AccountID>
         <AccountIDPub>173</AccountIDPub>
         <EmployeeSurname>XXXX</EmployeeSurname>
         <EmployeeFirstName>Sharon</EmployeeFirstName>
         <EmployeeDOB>07/12/1955</EmployeeDOB>
         <DateLastPaidTo>02/01/2009</DateLastPaidTo>
         <ContributionType>Personal</ContributionType>
         <ContributionAmount>200.0</ContributionAmount>
      </Contribution>

2. Key is <AccountIDPub> in the above nodes

3. The <ContributionType> can have 5 variations value(1,2,3,4,5)
   The XML shows only 2 <ContributionType> it can have uptil 5.
   The other I set them 0 for display (please see below)

The XSL I have written at the moment displays this as follows

AcNo. Name      DOB     Comp Emp   Volu   Salary  Personal Spouse Total
------------------------------------------------------------------------
173   Sharon 07/12/1955 400.0      0        0        0      0    400.0
173   Sharon 07/12/1955   0        0       0       200.0    0    200.0

What would be the ideal way to get an output in a single row?
(Including adding the total)

AcNo. Name     DOB        Comp Emp  Volu  Salary Personal Spouse  Total
-------------------------------------------------------------------------
173  Sharon 07/12/1962     400.0     0       0    200.0      0    600.0

1. Should this be merged into a single XML first and then displayed in
a loop I guess I might need to do this in 2 passes...?

I understand that I can use a key (AcNo) and iterate, wasn't sure if there
were cleaner approach.

Any pointers appreciated....

Regards
Sunder


      Make Yahoo!7 your homepage and win a trip to the Quiksilver
Pro. Find out more

Current Thread