Reputation: 3545
I'm new to XSL, and i'm wrote next code for counting sum of Win values.
<xsl:variable name="WinAmount">
<xsl:number value="number(0)"/>
<xsl:for-each select="Event">
<xsl:if test="SpinTheReelsInfo">
<xsl:number value="number(number($WinAmount) + number(SpinTheReelsInfo/Win))"/>
</xsl:if>
<xsl:if test="SpinFreeReelsInfo">
<xsl:number value="number(number($WinAmount) + number(SpinFreeReelsInfo/Win))"/>
</xsl:if>
</xsl:for-each>
</xsl:variable>
<xsl:value-of select="$WinAmount"/>
in my xml file win tags are matched to the next values.
<Win>0</Win>
....
<Win>20</Win>
.....
<Win>200</Win>
But the result is 121201 I'm think it's because numbers concatenated and because every number incremented.
But why is this happening? And how can i sum them? Which operator can i use for this? PLease, help me! Thank you!
Update: my XML
<Game>
<GameSeqNo>1</GameSeqNo>
<Event>
<Time>2012-12-20T08:24:26Z</Time>
<SpinTheReelsInfo>
<Win>0</Win>
<JP>0</JP>
</SpinTheReelsInfo>
</Event>
<Event>
<Time>2012-12-20T08:24:42Z</Time>
<PickFieldInfo>
</PickFieldInfo>
</Event>
<Event>
<Time>2012-12-20T08:25:07Z</Time>
<SpinFreeReelsInfo>
<Win>20</Win>
<JP>0</JP>
</SpinFreeReelsInfo>
</Event>
<Event>
<Time>2012-12-20T08:25:18Z</Time>
<SpinFreeReelsInfo>
<Win>200</Win>
<JP>0</JP>
</SpinFreeReelsInfo>
</Event>
</Game>
Upvotes: 0
Views: 9160
Reputation: 167696
I think my suggestion in the comment suffices, here is a complete stylesheet:
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:template match="Game">
<xsl:value-of select="sum(Event/SpinTheReelsInfo/Win | Event/SpinFreeReelsInfo/Win)"/>
</xsl:template>
</xsl:stylesheet>
Output is 220
.
Upvotes: 3