Copied to clipboard

Flag this post as spam?

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


  • Jan 54 posts 74 karma points
    Jul 02, 2010 @ 14:40
    Jan
    0

    Macro = Adding values from different pages together

    hey - pretty noobish with this here xslt

    i got some pages that each have a value "votes"

    i need to get all these values from every pages added together

    is there a way to do that with a macro ? collect all values and add them together?

  • Chriztian Steinmeier 2798 posts 8788 karma points MVP 8x admin c-trib
    Jul 02, 2010 @ 15:02
    Chriztian Steinmeier
    0

    Hi Jan,

    You can do that with the sum() function - something like this (assuming 'votes' is a property):

    <xsl:value-of select="sum(//data[@alias = 'votes'])" />

    or, if you're using Umbraco 4.5:

    <xsl:value-of select="sum(//votes)" />

    It's a 'heavy' call because of the descendant axis, but having no further details regarding the structure, this is how you'd do it.

    /Chriztian

  • Jan 54 posts 74 karma points
    Jul 02, 2010 @ 15:16
    Jan
    0

    I need to point the macro somehow to read from a specific page structure ?
    My folders are as such

    Root
            Webpage (only visible page)
                    PollList
                          Poll
                                Group 1 (contains property "votes")
                                Group 2 (contains property "votes")
                                Group 3 (contains property "votes")
                                Group 4 (contains property "votes")

    i need to get the values from the groups (they contain a property with a numerial value)
    so how do i write the macro to pick up the values from all "pages" under the poll folder

    none of these pages are visible its only the webpage itself that has a macro that shows the poll results - (a package i installed which unfortunately doesnt add up total value)

     

    hope you can help thanx!

  • Jan 54 posts 74 karma points
    Jul 02, 2010 @ 15:18
    Jan
    0

    <xsl:for-each select="umbraco.library:GetXmlNodeById(1363)/node [string(data [@alias='umbracoNaviHide']) != '1']">

    <xsl:value-of select="sum(//data[@alias = 'votes'])" />

    </xsl:for-each>

     

    this is what i have gotten so far - unfortunately it shows the results Each time for each vote type. need to only show it once

  • Chriztian Steinmeier 2798 posts 8788 karma points MVP 8x admin c-trib
    Jul 02, 2010 @ 15:27
    Chriztian Steinmeier
    2

    Hi again,

    First, grab the nodes to summarize votes from in a variable:

    <xsl:variable name="voteNodes" select="umbraco.library:GetXmlNodeById(1363)/node[not(data[@alias = 'umbracoNaviHide'] = 1)]" />

    Output sum of votes:

    <xsl:value-of select="sum($voteNodes/data[@alias = 'votes'])" />

    /Chriztian

  • Jan 54 posts 74 karma points
    Jul 02, 2010 @ 15:36
    Jan
    0

    Thanx a bunch Chriztian that did it

Please Sign in or register to post replies

Write your reply to:

Draft