One of my blog reader asked my help to resolve a mapping to find a cumulative sum inside an existing Loop. The Source Xml Structure is as follows


<Details>



<Detail>



<Code>1</Code>


<Amount>200</Amount>


</Detail>


<Detail>



<Code>2</Code>


<Amount>1200</Amount>


</Detail>


<Detail>



<Code>1</Code>


<Amount>200</Amount>


</Detail>


</Details>


The Expected result is as follows. If you see the Amount has to be added for the same <Code> values.


<Details>



<Detail>



<Code>1</Code>


<Amount>400</Amount>


</Detail>


<Detail>



<Code>2</Code>


<Amount>1200</Amount>


</Detail>


</Details>


Even though this appears to be simple, it’s quite hard to do this inside Biztalk mapper without writing Inline XSLT.The reason is that there needs to be flattening (Should not create duplicate <Code> nodes) combined with Cumulative sum.


I found a way using some global variables to resolve this. Even though it might not be the best way, it can help if you do not want to write XSLT inside the mapper. If you are interested, you can download the solution from here