Instead of selecting the years, go for the actual Documents - here's a simple setup with a template for the "group" wrapper (e.g. where you print the year) and another for the Documents:
Yeah the $currentPage missing as my way of checking you :-) (Not... sorry 'bout that.)
So reasons the above wouldn't work/only return 1 result could be that there's maybe only a single Document node below $currentPage (fix by adding the double slash: $currentPage//Document[etc...]
About the count() thing -- I wrote an elaborate explanation here about that. It's part of an evil trick to find the distinct values for a given key.
yet another xsl:key question
been looking at this all day and i mean *all* day
not getting it sorry
read quite a few posts about it but the syntax is beating me
it's quite simple what i want to do using the muenchian thingy
i have a list of documents, and i want to group them by year, they have a date picker property
the XSLT I have looks a bit like this:
<xsl:param name="currentPage"/>
<xsl:key name="years" match="documentDate" use="substring(.,1,4)" />
<xsl:template match="/">
<xsl:for-each select="$currentPage/Document/documentDate [
generate-id() = generate-id(key('years', substring(.,1,4))[1])
]">
<h1><xsl:value-of select="../@nodeName"/></h1>
<xsl:for-each select="key('years',substring(.,1,4))">
<h2>
<xsl:value-of select="."/>
</h2>
<p>
<xsl:value-of select="substring(.,1,4)"/>
</p>
</xsl:for-each>
</xsl:for-each>
</xsl:template>
something is not right here, presently i just get the first result only and nothing else
all suggestions very gratefully received
J
Hi John,
Instead of selecting the years, go for the actual Documents - here's a simple setup with a template for the "group" wrapper (e.g. where you print the year) and another for the Documents:
/Chriztian
oh brilliant thank you
i'll give this a try now
how are you so on it :) ?
that's such a nicely written piece of xslt, a joy to read
sadly tho i still only get the top result
not the first node but the first by date value of documentDate
the first thought I had was that I hadn't done a republish for a while, and in a way I am relieved it wasn't that :)
made one very small change to the script above, presuming this is ok to say
I'm struggling to understand the point of the
[count(. | key('Docs-by-Year', substring(documentDate, 1, 4))[1]) = 1]
bit.
why test the count = 1?
Hi John,
Yeah the $currentPage missing as my way of checking you :-) (Not... sorry 'bout that.)
So reasons the above wouldn't work/only return 1 result could be that there's maybe only a single Document node below $currentPage (fix by adding the double slash: $currentPage//Document[etc...]
About the count() thing -- I wrote an elaborate explanation here about that. It's part of an evil trick to find the distinct values for a given key.
Let me know if it still doesn't work...
/Chriztian
is working on a reply...