Copied to clipboard

Flag this post as spam?

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


  • Claushingebjerg 939 posts 2574 karma points
    Aug 14, 2012 @ 16:20
    Claushingebjerg
    0

    Summing up values from DataType Grid, based on node id

    Im doing a sports site, where i need to sum up goals scored by the players across the season.

    Ive used the Ucomponents DataType grid, selecting the player node, and entering the number of goals scored by the player on each match. So far so good.

    The xml from the matces across the site looks like so

    <spillere>
      <items>
          <item id="1" sortOrder="0">
              <spiller nodeName="Spiller" nodeType="1034">1294</spiller>
              <maal nodeName="Mål" nodeType="-88">5</maal>
          </item>
          <item id="2" sortOrder="1">
              <spiller nodeName="Spiller" nodeType="1034">1319</spiller>
              <maal nodeName="Mål" nodeType="-88">3</maal>
          </item>
          <item id="3" sortOrder="0">
              <spiller nodeName="Spiller" nodeType="1034">1294</spiller>
              <maal nodeName="Mål" nodeType="-88">10</maal>
          </item>
      </items>
    </spillere>

    Im able to get all goals scored by all player by doing:

    <xsl:value-of select="sum($currentPage/ancestor::root//maal)"/>

    Which returns 18

    So i wanna sum up goals scored only by a certain node id, lets say 1294. This should return "15"

    I've tried the following, but it doesnt work...

    <xsl:value-of select="sum($currentPage/ancestor::root//maal [$currentPage/ancestor::root//spiller='1294'])"/>

    Any ideas?

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Aug 14, 2012 @ 17:02
    Chriztian Steinmeier
    1

    Hi Claus,

    You're thinking the right thing, but going all the way back to <root> and then using the double-slash will go through every single node (documents *and* properties!) in the site, looking for a <spiller> with the content '1294'. It will succeed, so you end up counting every <maal>. Instead, you need to pick the <maal> based on it's <spiller> value, so you only get those you want...

    It's always a good idea to "scope" selections, e.g. setting a spillere variable to point to all the properties you need to search through - this one takes all <spillere> properties from currentPage and its siblings - you can adjust this to your specific setup:

    <xsl:variable name="spillere" select="$currentPage/../*[@isDoc]/spillere" />

     

    When you have all the properties in a nodeset, you can now select all the <maal> data that has a sibling <spiller> with the specified id, e.g.:

    <xsl:value-of select="sum($spillere//maal[../spiller = 1294])" />

     

    (It's not as expensive to use the double-slash here, because all the nodes in the $spillere nodeset only have the items/item structure)

    /Chriztian 

  • Claushingebjerg 939 posts 2574 karma points
    Aug 14, 2012 @ 17:23
    Claushingebjerg
    0

    SCOOOOORE!

  • Claushingebjerg 939 posts 2574 karma points
    Aug 14, 2012 @ 19:51
    Claushingebjerg
    0

    Arhhhhhg.

    Next thing i need to know how many matches player id 1294 has played in...

    I think something like this, which as you probably gessed, doesnt work...

    <xsl:value-of select="count($currentPage/following::*[@isDoc] [$spillere//spiller = 1294])" />
  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Aug 14, 2012 @ 20:54
    Chriztian Steinmeier
    0

    Haha - it never ends :-)

    Well, I gues we'll need to know a little it more about the structure then...

    Does matches have a separate doctype, so each match is a document?

    /Chriztian

  • Claushingebjerg 939 posts 2574 karma points
    Aug 15, 2012 @ 07:35
    Claushingebjerg
    0

    Yes each match is a node of the document type "Kamp"

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Aug 15, 2012 @ 09:46
    Chriztian Steinmeier
    1

    Allrighty then,

    I'm guessing all your <Kamp> documents are below a common source node, so again, start by getting a reference to those - here's my version, but you can do GetXmlNodeById() or pass it in as a macro param - you know the possibilities, I'm sure:  

    <xsl:variable name="kampe" select="$siteRoot/Kampe/Kamp" />

    (I always have a siteRoot variable set up something like $currentPage/ancestor-or-self::*[@level = 1])

    Then it's a question of doing almost what you did, though *not* using the $spillere variable, but the spillere *property* - the variable has them all, remember? So using that would return true() everytime. So:

    <xsl:value-of select="count($kampe[spillere//spiller = 1294])" />

    /Chriztian

  • Claushingebjerg 939 posts 2574 karma points
    Aug 15, 2012 @ 10:19
    Claushingebjerg
    0

    Hmmmmm nice!

    Too bad i cant mark the topic solved twice :)

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Aug 15, 2012 @ 10:26
    Chriztian Steinmeier
    0

    No worries - I'm not in it for the karma.

    I'm in it for the beer :-)

    /Chriztian

  • Claushingebjerg 939 posts 2574 karma points
    Aug 15, 2012 @ 11:12
    Claushingebjerg
    0

    Ohhhh i see. Well that can be arranged :)

Please Sign in or register to post replies

Write your reply to:

Draft