I'm trying to list a series of article pages, under their relevant month headings. Having read elsewhere that XSLT grouping is a little tricky, I'm opting for the simpler approach of just looping through the articles (ordered by date) and getting the month name of the current article and the month name of the preceding sibling article, and if they're different, writing out the month as a header. This should then format all of my articles under their relevant month heading.
However, the bit of code I'm using to get the month name of the sibling article isn't working:
A couple of things. First, you probably need to use the library function around the whole result, not just the data portion.
Another possibility is the fact that the preceding-sibling call actually gets you all preceding siblings. I believe preceding-siblings does get them in reverse order, so you would likely want the first one. So try something like:
So it's clearly putting the h2 tags in where it sees fit, but it's just not getting the previous sibling correctly to set a correct value for lastMonth.
Ahhh yes. Even though you are getting the in sorted order, the tree it is checking for siblings is still in its original order. Try doing this before your for-each:
Since you've limited the node context to the node-set created in the sortedNodes variable, you'll need to grab the wanted item using the original context - try this:
Get property of sibling within loop
Hi,
I'm trying to list a series of article pages, under their relevant month headings. Having read elsewhere that XSLT grouping is a little tricky, I'm opting for the simpler approach of just looping through the articles (ordered by date) and getting the month name of the current article and the month name of the preceding sibling article, and if they're different, writing out the month as a header. This should then format all of my articles under their relevant month heading.
However, the bit of code I'm using to get the month name of the sibling article isn't working:
I've looked in the wiki but this area isn't covered yet. Can anyone tell my what's wrong with the above code?
Thanks!
The wiki article I'm taking about is this one, by the way: http://umbraco.org/documentation/books/xslt-basics/xpath-axes-and-their-shortcuts.
Hey dan,
A couple of things. First, you probably need to use the library function around the whole result, not just the data portion.
Another possibility is the fact that the preceding-sibling call actually gets you all preceding siblings. I believe preceding-siblings does get them in reverse order, so you would likely want the first one. So try something like:
Thanks webangelo, that's brought me a step nearer, but it still doesn't seem to be behaving as it should. The full code I have is essentially this:
There are 6 articles in my site - 5 in April and 1 in March, so I'd expect the output to be like this:
However, it's actually doing this:
Any ideas would be greatly appreciated, thanks!
Sorry that first block should be:
The exact output, with the current and last month values, in case it's useful is:
So it's clearly putting the h2 tags in where it sees fit, but it's just not getting the previous sibling correctly to set a correct value for lastMonth.
Ahhh yes. Even though you are getting the in sorted order, the tree it is checking for siblings is still in its original order. Try doing this before your for-each:
And for your for-each try:
That's great, thanks! I modified slightly, so for future reference I updated the code above to:
Actually, I also need to get a value from the parent node within the loop, but this isn't working as I would have expected. Here's what I'm doing:
It doesn't seem to pick up anything for the 'projectColour' - the rest works fine. How do I access data from the parent node when using this method?
Thanks
Hi - Dan,
Since you've limited the node context to the node-set created in the sortedNodes variable, you'll need to grab the wanted item using the original context - try this:
If that doesn't work (bet you it does, though) you can pull in the context from $currentPage:
/Chriztian
The first one worked perfectly, thanks Chriztian. I'm sorry I can't mark your post as solved - but I've voted it up anyhow. Much appreciated.
No worries - it's not "all about the money", you know :-)
/Chriztian
is working on a reply...