Calling Childnodes in a Loop based on a Specific Value
Hello Everyone! Basic info first. I am using XSLT so far and am using Umbraco 4.7 and this is kind of a 2 parter. Please click on the images to enlarge them.
PART 1
First I am wanting to display all nodes of a specific type (Award Categories) on the page. You will see two "award categories" in my file tree and on my screenshot. (Outstanding Alumni & Professional Acievement)
Then I want to list all of the Award Winners for those categories (childnodes) under each category. See the image below.
So far I have been able to hardcode the childnode values in there but not get it to pull the actual dynamic childnodes. Here is my code so far...
I have hardcoded the nodeID in there... That needs to call the childnodes of the Award Category dynamically instead.
PART 2
I want to be able to select a specific year of winners to display. So in the Award Category DocType I have a dropdown list of years to select from. In the image below you'll see I have 2011 selected for the "Outstanding Alumni Award" category. That means I only want to show winners in 2011 in the list.
In the image above you'll see 2 of my sample "award winners" Todd should be displayed as he won an award in 2011 which matches the category selection. Kenneth should not show up because he only won an award in 2009.
I used a "Tag" datatype in case the people won an award more than 1 year. Does anyone see a problem of using a dropdown list to select the date to display in the category and then matching it to a TAG value?
Assuming that you want those to display on the Alumni-page, you could simply use for-eaches.
<!-- Loop through the currentPages children of type AwardCategory --> <xsl:for-each select="$currentPage/AwardCategory"> <!-- Loop through the children of AwardCategory of type AwardWinner-Full --> <xsl:for-each select="./AwardWinner-Full"> </xsl:for-each> </xsl:for-each>
Does this make sense or do I not understand your structure right?
@year is the property-name of the awardwinner and $year is the selected year on the parent. I'm not sure how the xml is structered on the tags, but if you do a xsl:copy-of then you'll get the entire xml spit out
Does this get you going? If not, post a bit xml from the copy-of so I can see the properties. I can then make a bit better xslt :)
I've been working to intergrate that second part to my script this morning but I haven't had any luck yet. I'm wondering if because my indiviual award winner is using the tags datatype that it might not be going as smoothly as I had hoped. Of course I might just be missing it too.. So here's what I got working..
The alias for the Award Category Display Year is = displayAwardsWinners (which is a dropdownlist single selection) and the alias for the Individual persons winning years is = awardWonTheseYears (which is a TAG dataType)
Assuming displayAwardsWinners is a field on the AwardCategory document that contains the year you want to show?
Also I'm not positive that the current() will work since you are using nested for-each loops. If you have trouble, try dumping it into a variable first:
Calling Childnodes in a Loop based on a Specific Value
Hello Everyone!
Basic info first. I am using XSLT so far and am using Umbraco 4.7 and this is kind of a 2 parter. Please click on the images to enlarge them.
PART 1
First I am wanting to display all nodes of a specific type (Award Categories) on the page. You will see two "award categories" in my file tree and on my screenshot. (Outstanding Alumni & Professional Acievement)
Then I want to list all of the Award Winners for those categories (childnodes) under each category. See the image below.
So far I have been able to hardcode the childnode values in there but not get it to pull the actual dynamic childnodes. Here is my code so far...
You can see that on this line:
I have hardcoded the nodeID in there... That needs to call the childnodes of the Award Category dynamically instead.
PART 2
I want to be able to select a specific year of winners to display. So in the Award Category DocType I have a dropdown list of years to select from. In the image below you'll see I have 2011 selected for the "Outstanding Alumni Award" category. That means I only want to show winners in 2011 in the list.
In the image above you'll see 2 of my sample "award winners" Todd should be displayed as he won an award in 2011 which matches the category selection. Kenneth should not show up because he only won an award in 2009.
I used a "Tag" datatype in case the people won an award more than 1 year. Does anyone see a problem of using a dropdown list to select the date to display in the category and then matching it to a TAG value?
Thank you for your time and help in advance.
Assuming that you want those to display on the Alumni-page, you could simply use for-eaches.
Does this make sense or do I not understand your structure right?
Peter
I am actually posting all of this information on the Awards page. But I did use your line:
which I think will work to answer PART 1 of my issue... just the tricky is part left! ;-)
I'll give ya a High Five though for that
Part 2 shouldn't be that hard either then ;)
<xsl:for-each select="./AwardWinner-Full[ @year = $year ]">
@year is the property-name of the awardwinner and $year is the selected year on the parent. I'm not sure how the xml is structered on the tags, but if you do a xsl:copy-of then you'll get the entire xml spit out
Does this get you going? If not, post a bit xml from the copy-of so I can see the properties. I can then make a bit better xslt :)
Peter
Hello Peter,
I've been working to intergrate that second part to my script this morning but I haven't had any luck yet. I'm wondering if because my indiviual award winner is using the tags datatype that it might not be going as smoothly as I had hoped. Of course I might just be missing it too.. So here's what I got working..
The alias for the Award Category Display Year is = displayAwardsWinners (which is a dropdownlist single selection)
and the alias for the Individual persons winning years is = awardWonTheseYears (which is a TAG dataType)
Thanks for your help.
Hi,
The tags datatype stores the tag as comma separated values, ie (2010,2011,2009), so you can't really do a simple equals comparison to filter.
But you could try using the contains function instead:
Assuming displayAwardsWinners is a field on the AwardCategory document that contains the year you want to show?
Also I'm not positive that the current() will work since you are using nested for-each loops. If you have trouble, try dumping it into a variable first:
Hope this helps,
Tom
Yeah, looks like that did the trick. They both seem to work quite well. Thanks Tom
is working on a reply...