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
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:
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:
(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:
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
Im able to get all goals scored by all player by doing:
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...
Any ideas?
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:
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.:
(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
SCOOOOORE!
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...
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
Yes each match is a node of the document type "Kamp"
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:
(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:
/Chriztian
Hmmmmm nice!
Too bad i cant mark the topic solved twice :)
No worries - I'm not in it for the karma.
I'm in it for the beer :-)
/Chriztian
Ohhhh i see. Well that can be arranged :)
is working on a reply...