I'm trying desperately to get a unique list of year/month published dates from my content. All the examples that I've seen are advising me to use 'keys' but however hard I try I can't get any output whatsoever using this approach.
Here's my basic XSLT what produces a list of yyyy-mm outputs.
Yeah, it's not the simplest thing in the world, but here's a starter to get you going:
<xsl:param name="currentPage" />
<!-- Index documents by their year+month combination -->
<xsl:key name="documentsByMonth" match="*[@isDoc]" use="substring(@updateDate, 1, 7)" />
<!-- Grab news from somewhere -->
<xsl:variable name="news" select="$currentPage/*[@isDoc]" />
<xsl:template match="/">
<xsl:for-each select="$news/*[@isDoc][count(. | key('documentsByMonth', substring(@updateDate, 1, 7))[1]) = 1]">
<xsl:sort select="@updateDate" data-type="text" order="descending" />
<!-- Render stuff for "group" only (e.g., a header or similar) -->
<xsl:apply-templates select="." mode="group" />
<!-- Render items in group -->
<xsl:apply-templates select="key('documentsByMonth', substring(@updateDate, 1, 7))" mode="item">
<xsl:sort select="@updateDate" data-type="text" order="descending" />
</xsl:apply-templates>
</xsl:for-each>
</xsl:template>
<xsl:template match="*[@isDoc]" mode="group">
<!-- Output for header -->
<xsl:value-of select="substring(@updateDate, 1, 7)" />: <xsl:text />
</xsl:template>
<xsl:template match="*[@isDoc]" mode="item">
<!-- Output for a single item -->
<xsl:value-of select="@nodeName" />, <xsl:text />
</xsl:template>
If all your "news" nodes have the same document type alias, you can substitute *[@isDoc] for that document type alias (everywhere) to optimize the thing (probably only noticable with huge sets of nodes, though).
Could you post your XSLT - either here or perhaps a link to a Gist - keys only return results within the document that contains the current context node, which is mangled a little by the way Umbraco does XSLT transforms.
So I'll need to see exactly what's going on to give any good pointers...
Kidding aside - one reason could be that it's not running as a macro on the "News Repository" node?
The $news variable selects all the children of $currentPage, which forces it to only work on the repository node - if you need it to work from everywere, you need to do something like this:
Hi Mate (Sorry for the trouble!) but still not getting any output.
Here's a picture of my content tree showing the NewsRepository and the NewsItems (it's the NewsItem's that I'm trying to get a unique list of published/updated dates.
Unique list of nodes XSLT
Hi all,
I'm trying desperately to get a unique list of year/month published dates from my content. All the examples that I've seen are advising me to use 'keys' but however hard I try I can't get any output whatsoever using this approach.
Here's my basic XSLT what produces a list of yyyy-mm outputs.
Could someone give me some pointers please on how I can get a distinct list of yyyy-mm please?
thanks, Craig
Hi Craig,
Yeah, it's not the simplest thing in the world, but here's a starter to get you going:
If all your "news" nodes have the same document type alias, you can substitute
*[@isDoc]
for that document type alias (everywhere) to optimize the thing (probably only noticable with huge sets of nodes, though).Hope that helps,
/Chriztian
Hi Chriztian,
Thanks for that but I'm not getting any output whatsoever! (no errors either though!).
The nodetype is NewsItem and this is an image of my content tree
Thanks again
Hi Craig,
Alright - then we'll need to do some debugging...
Could you post your XSLT - either here or perhaps a link to a Gist - keys only return results within the document that contains the current context node, which is mangled a little by the way Umbraco does XSLT transforms.
So I'll need to see exactly what's going on to give any good pointers...
/Chriztian
Hi, here's my full XSLT (which is basically what you've pointed me to with a couple of amendments)
I just spotted an error right away:
In the for-each, remove the
/*[@isDoc]
from the select, as it tries to get all nodes that are children of the news items. It should look like this:<xsl:for-each select="$news[count( ...
/Chriztian
Done that mate but still nothing :(
I don't believe you - it should work! :-)
Kidding aside - one reason could be that it's not running as a macro on the "News Repository" node?
The
$news
variable selects all the children of$currentPage
, which forces it to only work on the repository node - if you need it to work from everywere, you need to do something like this:/Chriztian
Hi Mate (Sorry for the trouble!) but still not getting any output.
Here's a picture of my content tree showing the NewsRepository and the NewsItems (it's the NewsItem's that I'm trying to get a unique list of published/updated dates.
thanks again
No worries :)
So with that content tree, you'd need to set the newsRepository variable like this:
(assuming the others are set according to the earlier post)
/Chriztian
Oooh think we might be getting somewhere.....
I think that you've nailed it matey :) Now I just gotta convert the month year to full month and year and it's all happy days!
is working on a reply...