sub-total and grand-total
Link for thread in forum
To get the sub-total and grand-total for xml, which has been grouped by two level.
example is here
[Root]
[item]
[item_detail]WORKER[/item_detail]
[amount]100[/amount]
[/item]
[item]
[item_detail]WORKER[/item_detail]
[amount]100[/amount]
[/item]
[item]
[item_detail]WORKER[/item_detail]
[amount]100[/amount]
[/item]
[item]
[item_detail]WORKER[/item_detail]
[amount]100[/amount]
[/item]
[item]
[item_detail]WORKER[/item_detail]
[amount]100[/amount]
[/item]
[item]
[category]car[/category]
[item_detail]LABOUR[/item_detail]
[name]one[/name]
[amount]100[/amount]
[/item]
[item]
[category]car[/category]
[item_detail]LABOUR[/item_detail]
[name]two[/name]
[amount]100[/amount]
[/item]
[item]
[category]phone[/category]
[item_detail]LABOUR[/item_detail]
[name]three[/name]
[amount]100[/amount]
[/item]
[item]
[category]parts[/category]
[item_detail]LABOUR[/item_detail]
[name]four[/name]
[amount]100[/amount]
[/item]
[item]
[category]parts[/category]
[item_detail]LABOUR[/item_detail]
[name]five[/name]
[amount]100[/amount]
[/item]
[/Root]
==============
[?for-each:item[item_detail=’LABOUR’]?]
[?category?] - [?name?] - [?amount?]
[?end for-each?]
Sum of all items of type LABOR = [?sum(item[item_detail=’LABOUR’]/amount)?]
---------------
out put will be like
car - one - 100
car - two - 100
phone - three - 100
parts - four - 100
parts - five - 100
Sum of all items of type LABOR = 500
==========================
[?for-each-group:item[item_detail=’LABOUR’]; category?]
[?category?] - - [?sum(current-group()/amount)?]
[?end for-each?]
--------------
sum of category car - - 200
sum of category phone - - 100
sum of category parts - - 200
==============
[?for-each-group:item;item_detail?]
[?item_detail?]
[?for-each-group:current-group();category?]
Total for category : [?category?] = [?sum(current-group()/amount)?]
[?end for-each-group?]
Total for Item_detail [?item_detail?] = [?sum(current-group()/amount)?]
[?end for-each-group?]
============
output
------------
WORKER
Total for category : = 500
Total for Item_detail WORKER = 500
LABOUR
Total for category : car = 200
Total for category : phone = 100
Total for category : parts = 200
Total for Item_detail LABOUR = 500
To get the sub-total and grand-total for xml, which has been grouped by two level.
example is here
[Root]
[item]
[item_detail]WORKER[/item_detail]
[amount]100[/amount]
[/item]
[item]
[item_detail]WORKER[/item_detail]
[amount]100[/amount]
[/item]
[item]
[item_detail]WORKER[/item_detail]
[amount]100[/amount]
[/item]
[item]
[item_detail]WORKER[/item_detail]
[amount]100[/amount]
[/item]
[item]
[item_detail]WORKER[/item_detail]
[amount]100[/amount]
[/item]
[item]
[category]car[/category]
[item_detail]LABOUR[/item_detail]
[name]one[/name]
[amount]100[/amount]
[/item]
[item]
[category]car[/category]
[item_detail]LABOUR[/item_detail]
[name]two[/name]
[amount]100[/amount]
[/item]
[item]
[category]phone[/category]
[item_detail]LABOUR[/item_detail]
[name]three[/name]
[amount]100[/amount]
[/item]
[item]
[category]parts[/category]
[item_detail]LABOUR[/item_detail]
[name]four[/name]
[amount]100[/amount]
[/item]
[item]
[category]parts[/category]
[item_detail]LABOUR[/item_detail]
[name]five[/name]
[amount]100[/amount]
[/item]
[/Root]
==============
[?for-each:item[item_detail=’LABOUR’]?]
[?category?] - [?name?] - [?amount?]
[?end for-each?]
Sum of all items of type LABOR = [?sum(item[item_detail=’LABOUR’]/amount)?]
---------------
out put will be like
car - one - 100
car - two - 100
phone - three - 100
parts - four - 100
parts - five - 100
Sum of all items of type LABOR = 500
==========================
[?for-each-group:item[item_detail=’LABOUR’]; category?]
[?category?] - - [?sum(current-group()/amount)?]
[?end for-each?]
--------------
sum of category car - - 200
sum of category phone - - 100
sum of category parts - - 200
==============
[?for-each-group:item;item_detail?]
[?item_detail?]
[?for-each-group:current-group();category?]
Total for category : [?category?] = [?sum(current-group()/amount)?]
[?end for-each-group?]
Total for Item_detail [?item_detail?] = [?sum(current-group()/amount)?]
[?end for-each-group?]
============
output
------------
WORKER
Total for category : = 500
Total for Item_detail WORKER = 500
LABOUR
Total for category : car = 200
Total for category : phone = 100
Total for category : parts = 200
Total for Item_detail LABOUR = 500
Comments