Grouping & summing

Subject: Grouping & summing
From: "Martin K. Borgars" <martin.borgars@xxxxxxxxxxxxxxx>
Date: Fri, 18 Jun 2004 12:27:52 +0100
I have a piece of XML which looks like this: -

<application>
       <personal_client id="pc1">
             <full_name>Mr Test9</full_name>
       </personal_client>
       <personal_client id="pc2">
             <full_name>Mrs Test9</full_name>
       </personal_client>
       <product>
             <risk_benefit id="rb1" type="Permanent Health Insurance">
                    <risk_cover>
                           <life_assured personal_client_id="pc1"/>
                    </risk_cover>
                    <tpsdata>
                           <provider_component>
                                 <calculated_sa>600</calculated_sa>
                           </provider_component>
                    </tpsdata>
             </risk_benefit>
             <risk_benefit id="rb2" type="Permanent Health Insurance">
                    <risk_cover>
                           <life_assured personal_client_id="pc1"/>
                           <life_assured personal_client_id="pc2"/>
                    </risk_cover>
                    <tpsdata>
                           <provider_component>
                                 <calculated_sa>800</calculated_sa>
                           </provider_component>
                    </tpsdata>
             </risk_benefit>
             <risk_benefit id="rb3" type="Permanent Health Insurance">
                    <risk_cover>
                           <life_assured personal_client_id="pc1"/>
                    </risk_cover>
                    <tpsdata>
                           <provider_component>
                                 <calculated_sa>1000</calculated_sa>
                           </provider_component>
                    </tpsdata>
             </risk_benefit>
             <risk_benefit id="rb4" type="Life And Health">
                    <risk_cover>
                           <life_assured personal_client_id="pc2"/>
                    </risk_cover>
                    <tpsdata>
                           <provider_component>
                                 <calculated_sa>900</calculated_sa>
                           </provider_component>
                    </tpsdata>
             </risk_benefit>
       </product>
</application>
 

In my XSL, I want to sum the 'calculated_sa' for each
'life_assured[personal_client_id]' grouped by 'risk_benefit[type]'. If there
is more than 1 'life_assured[personal_client_id]' associated with a
'risk_benefit' then the 'calculated_sa' should be included for each
'life_assured[personal_client_id]'.

 
So, in this example I want to end up with something like this

life_assured[personal_client_id="pc1"] risk_benefit[type="Permanent Health
Insurance"]               Total Sum Assured = 2400 (i.e. 600 + 800 + 1000)

life_assured[personal_client_id="pc2"] risk_benefit[type="Permanent Health
Insurance"]               Total Sum Assured = 800

life_assured[personal_client_id="pc2"] risk_benefit[type=" Life And Health
"]                                  Total Sum Assured = 900

Any suggestions with suitable XPATH or XSL would be greatly appreciated.
 
Many thanks

Martin K. Borgars



Current Thread