Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Magnus Jonsson 33 posts 53 karma points
    Oct 28, 2010 @ 13:24
    Magnus Jonsson
    0

    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.

    Does anybody have a suggestion?

     

    Best regards, Magnus

     

  • Rich Green 2246 posts 4008 karma points
    Oct 28, 2010 @ 13:33
    Rich Green
    0

    What version of Umbraco you using? 

    Can you share the XSLT you have tried so far.

    Rich

  • Magnus Jonsson 33 posts 53 karma points
    Oct 28, 2010 @ 13:35
    Magnus Jonsson
    0

    I'm on 4.5.2

    And this is what the XSLT looks like:

    <xsl:variable name="source" select="/macro/source"/>

    <xsl:template match="/">

    <!-- 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>
  • Chriztian Steinmeier 2798 posts 8788 karma points MVP 7x admin c-trib
    Oct 28, 2010 @ 13:40
    Chriztian Steinmeier
    0

    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

  • Magnus Jonsson 33 posts 53 karma points
    Oct 28, 2010 @ 13:42
    Magnus Jonsson
    0

    Hi,

    I'd like to sum the field: gameGjordaMal which is also displayed "node by node" in the row:

     Resultat: <xsl:value-of select="gameGjordaMal"/> - <xsl:value-of select="gameInslapptaMal"/><br/>

    /M

  • Rich Green 2246 posts 4008 karma points
    Oct 28, 2010 @ 13:44
    Rich Green
    0

    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

  • Magnus Jonsson 33 posts 53 karma points
    Oct 28, 2010 @ 13:45
    Magnus Jonsson
    0

    Yes Rich...that's exactly what I'm looking for

    /M

  • Rich Green 2246 posts 4008 karma points
    Oct 28, 2010 @ 14:00
    Rich Green
    0

    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

  • Magnus Jonsson 33 posts 53 karma points
    Oct 28, 2010 @ 14:03
    Magnus Jonsson
    0

    Rich!!!! It works perfectly!!!

    Thanks :)

Please Sign in or register to post replies

Write your reply to:

Draft