Thursday, 25 December 2014

xsl group by with when date to equals date from



I'm using xslt 2.0 for transformation to a new XML This is my xml Structure:



<?xml version="1.0" encoding="UTF-8"?>
<bills>
<bill id="1">
<rz_from>05.11.2011</rz_from>
<rz_to>31.12.2011</rz_to>
<rz_price_pro_unit>4</rz_price_pro_unit>
<rz_units>7</rz_units>
</bill>
<bill id="2">
<rz_from>1.1.2012</rz_from>
<rz_to>31.3.2012</rz_to>
<rz_price_pro_unit>4</rz_price_pro_unit>
<rz_units>9</rz_units>
</bill>
<bill id="3">
<rz_from>1.5.2012</rz_from>
<rz_to>31.12.2012</rz_to>
<rz_price_pro_unit>4</rz_price_pro_unit>
<rz_units>21</rz_units>
</bill>
<bill id="4">
<rz_from>1.1.2013</rz_from>
<rz_to>31.12.2013</rz_to>
<rz_price_pro_unit>5</rz_price_pro_unit>
<rz_units>45</rz_units>
</bill>
<bill id="5">
<rz_from>1.1.2014</rz_from>
<rz_to>31.12.2014</rz_to>
<rz_price_pro_unit>5</rz_price_pro_unit>
<rz_units>51</rz_units>
</bill>
</bills>


I need to group the bill nodes by these rules:




  • the price per unit is the same

  • the date (rz_from - 1 day) is equal to the date (rz_to) of the previous node

  • the count of units should by the sum of the grouped values



So the result should be:




  • Bill: 16 units - price 4 (bill 1+2)

  • Bill: 21 units - price 4 (bill 3)

  • Bill: 96 units - price 5 (bill 4+5)



No comments:

Post a Comment