Adding (sum) values from a property when looping X number of nodes
Hi,
I have a documentstructure that like this:
\Root \games \game1 \game2 \game3
I'm using a XSLT which is based on the "List subpages frrom changeable node" and when inserting the macro I'm using the contentpicker to point out the \games node. On each of the "game-nodes" (game1, game2, game3 etc.) I have a numeric property. I would like to add up (sum) this property in my XSLT but I just can't seem to figure it out. I guess the "sum()" function is the way to go but my XSLT knowledge is to shallow.
<!-- The fun starts here --> <ul> <xsl:for-each select="umbraco.library:GetXmlNodeById($source)/* [@isDoc and string(umbracoNaviHide) != '1']"> <li> <xsl:value-of select="gameMotstandare"/> <br/> Resultat: <xsl:value-of select="gameGjordaMal"/> - <xsl:value-of select="gameInslapptaMal"/><br/> Totalt: <!-- Here I like to display the total --> </li> </xsl:for-each> </ul> </xsl:template>
<xsl:variable name="total" select="sum(umbraco.library:GetXmlNodeById($source)/* [@isDoc and string(umbracoNaviHide) != '1' and name()='YourGameDocType']/gameGjordaMal)"/>
Adding (sum) values from a property when looping X number of nodes
Hi,
I have a documentstructure that like this:
I'm using a XSLT which is based on the "List subpages frrom changeable node" and when inserting the macro I'm using the contentpicker to point out the \games node. On each of the "game-nodes" (game1, game2, game3 etc.) I have a numeric property. I would like to add up (sum) this property in my XSLT but I just can't seem to figure it out. I guess the "sum()" function is the way to go but my XSLT knowledge is to shallow.
Does anybody have a suggestion?
Best regards, Magnus
What version of Umbraco you using?
Can you share the XSLT you have tried so far.
Rich
I'm on 4.5.2
And this is what the XSLT looks like:
Hi Magnus,
Which field(s) should be summed - is it the two fields you're showing in "Resultat: [FIELD1] - [FIELD2]", or something across the full site?
/Chriztian
Hi,
I'd like to sum the field: gameGjordaMal which is also displayed "node by node" in the row:
/M
Would I be correct in saying that you have a property on your game node that you would like the total of?
Like
Game 1 - 10
Game 2 - 15
Game 3 - 10
So the total you are looking for is 35?
RIch
Yes Rich...that's exactly what I'm looking for
/M
Should be something like this
<xsl:variable name="total" select="sum(umbraco.library:GetXmlNodeById($source)/* [@isDoc and string(umbracoNaviHide) != '1' and name()='YourGameDocType']/gameGjordaMal)"/>
<ul>
<xsl:for-each select="umbraco.library:GetXmlNodeById($source)/* [@isDoc and string(umbracoNaviHide) != '1']">
<li>
<xsl:value-of select="gameMotstandare"/> <br/>
Resultat: <xsl:value-of select="gameGjordaMal"/> - <xsl:value-of select="gameInslapptaMal"/><br/>
Totalt: <xsl:value-of select="$total"/>
</li>
</xsl:for-each>
</ul>
However Chriztian will certainly know the best way :)
Rich
Rich!!!! It works perfectly!!!
Thanks :)
is working on a reply...