I know I can do this by using a for-each and preceeding-sibling, but I'd like to try Muenchian grouping for a more elegant solution. I've tried the following, but just can't get it to work:
Where 'article years' is the name of the key, 'JournalArticle' is the document type alias and 'articleDate' is the data type alias of the date I want to group by.
Can anyone suggest what I'm doing wrong? I suspect it's to do with the 'match' field, but I've tried a few different things here to no avail.
Is articleDate a datepicker? If so I think you might need to add some Date Formatting in there to get the year. Here's code from something similar I did that should get you started:
Just to help you get through your initial attempt and provide a "Simple Muenchian Grouping" example (if such a thing exists :-) - 'coz you were off to a great start, actually...
Is there any reason why the Muenchian grouping examples always use the count() / union method and not the generate-id method?
I have been trying to get my head round the whole thing and Jeni Tennison's article here offers both as options; however, the count() / union variation is almost invariably used in examples.
Is it more efficient or is it just a style thing? I find the generate-id method more intuitive to read, but that's probably because I suck at set arithmetic :o)
Simple Muenchian grouping
Hi,
I have a list of journal articles on my site. I'd like to show an archive of these, grouped by year, so my rendered HTML will be something like:
I know I can do this by using a for-each and preceeding-sibling, but I'd like to try Muenchian grouping for a more elegant solution. I've tried the following, but just can't get it to work:
Where 'article years' is the name of the key, 'JournalArticle' is the document type alias and 'articleDate' is the data type alias of the date I want to group by.
Can anyone suggest what I'm doing wrong? I suspect it's to do with the 'match' field, but I've tried a few different things here to no avail.
Thanks
Hi Dan,
Is articleDate a datepicker? If so I think you might need to add some Date Formatting in there to get the year. Here's code from something similar I did that should get you started:
-Tom
Great, with a few mods that's sorted it! Thanks Tom.
Hi Dan,
Just to help you get through your initial attempt and provide a "Simple Muenchian Grouping" example (if such a thing exists :-) - 'coz you were off to a great start, actually...
<?xml version="1.0" encoding="utf-8" ?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:umb="urn:umbraco.library" exclude-result-prefixes="umb" > <xsl:output method="xml" indent="yes" omit-xml-declaration="yes" /> <xsl:param name="currentPage" /> <xsl:variable name="siteRoot" select="$currentPage/ancestor-or-self::*[@level = 1]" /> <!-- Select the root "folder" of JournalArticle documents here --> <xsl:variable name="articleRoot" select="$siteRoot/Journals" /> <!-- Creates index of all JournalArticles by year --> <xsl:key name="article-years" match="JournalArticle" use="substring(articleDate, 1, 4)" /> <xsl:template match="/"> <ul class="archive"> <xsl:for-each select="$currentPage/JournalArticle[count(. | key('article-years', substring(articleDate, 1, 4))[1]) = 1]"> <xsl:sort select="articleDate" data-type="text" order="descending" /> <xsl:variable name="year" select="substring(articleDate, 1, 4)" /> <li> <a href="{umb:NiceUrl(@id)}?year={$year}"> <xsl:value-of select="$year" /> </a> </li> </xsl:for-each> </ul> </xsl:template> </xsl:stylesheet>/Chriztian
A wonderful and very helpful reply, as always, thanks Chriztian.
Is there any reason why the Muenchian grouping examples always use the count() / union method and not the generate-id method?
I have been trying to get my head round the whole thing and Jeni Tennison's article here offers both as options; however, the count() / union variation is almost invariably used in examples.
Is it more efficient or is it just a style thing? I find the generate-id method more intuitive to read, but that's probably because I suck at set arithmetic :o)
@Rob: I have no idea - haven't tried to benchmark it - but now I'm curious, so I'll probably do some testing. Doubt there's much difference, though...
/Chriztian
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.