I need to multiply several pairs of values and sum them up, but all i get is a row of the numbers. (E.g: The numbers which i need to sum up are 12 and 13, what i need is 25, what i get is "1213") I already tried different kinds of typecasting and tried to build workarounds, but i can't get to a solution. (the value of the "$x" variable is the problem)
Here is my code:
let $hk := doc('http://etutor.dke.uni-linz.ac.at/etutor/XML?id=1')/handelskette
for $n in distinct-values($hk/kunden/kunde/bonStufe)
let $k := $hk/kunden/kunde[bonStufe=$n]
let $c := count($k)
let $r := $hk/rechnungen/rechnung[kundeNr=$k/@kundeNr]/rposition
let $x := 0
order by $n
return <bStufe val="{$n}">
<umsGesamt>{
for $i in $r
let $x := sum(xs:integer($i/einzelPreis) * xs:integer($i/menge))
return $x
}</umsGesamt>
<umsProKunde>{(:$x div :)$c}</umsProKunde>
</bStufe>
$i looks like (i would need sum(einzelPreis*menge)):
<rposition>
<ean>5-6661-000-0-00</ean>
<einzelPreis>500</einzelPreis>
<menge>3</menge>
</rposition>
My result looks like this:
<bStufe val="A">
<umsGesamt>150015752450140004507606001100</umsGesamt>
<umsProKunde>5</umsProKunde>
</bStufe>
<bStufe val="B">
<umsGesamt>2292250068006602200690070001200045001530</umsGesamt>
<umsProKunde>4</umsProKunde>
</bStufe>
<bStufe val="C">
<umsGesamt>29010001590130013502600150195012900320010003751000</umsGesamt>
<umsProKunde>4</umsProKunde>
</bStufe>
I would really appreciate some help.
Best Regards Lucas