Wednesday, February 4, 2015

Replacing $ in amount and calculating the sum of amount using OSB XQuery


XQuery Code Snippet:

let $in :=
<test>
{
for $repeat in $input/repeat
let $amount := $repeat/amount
return
<amount1>{fn:replace($amount,"\quot;,'')}</amount1>
}
</test>
return
sum($in/amount1)

Sample Input:

<input>
<repeat>
<amount>$100</amount>
</repeat>
<repeat>
<amount>100</amount>
</repeat>
</input>

Result : 200.0

P.S. An alternative to this lengthy approach will be updated as early as possible in this post.