Im trying to sort the sub nodes of a page by date, and the grouping them in sets of 3 wrapped in a div. I've got the grouping to work, but im at a bit of a loss as how to get the nodes sorted correctly... i would like to sort by the parameter "dato"
The trick is that you need to build a sorted version of the nodes because the following-sibling:: axis (and other axes) always works in document order. Here's something to work from:
<?xml version="1.0" encoding="utf-8" ?>
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:umbraco.library="urn:umbraco.library"
xmlns:make="urn:schemas-microsoft-com:xslt"
exclude-result-prefixes="umbraco.library make"
>
<xsl:output method="xml" indent="yes" omit-xml-declaration="yes" />
<xsl:param name="currentPage" />
<xsl:variable name="proxy-builder">
<xsl:for-each select="$currentPage/*[@isDoc][not(umbracoNaviHide = 1)]">
<xsl:sort select="dato" data-type="text" order="descending" />
<!-- Build a set of references in the correct sort order -->
<proxy><xsl:value-of select="@id" /></proxy>
</xsl:for-each>
</xsl:variable>
<xsl:variable name="proxies" select="make:node-set($proxy-builder)" />
<xsl:variable name="group-size" select="3" />
<xsl:template match="/">
<xsl:for-each select="$proxies/proxy[position() mod $group-size = 1]">
<div>
<ul>
<xsl:for-each select=". | following-sibling::proxy[position() < $group-size]">
<!-- Process the actual nodes -->
<xsl:apply-templates select="$currentPage/*[@id = current()]" />
</xsl:for-each>
</ul>
</div>
</xsl:for-each>
</xsl:template>
<!-- Template for single item -->
<xsl:template match="*[@isDoc]">
<li>
<h3><a href="{umbraco.library:NiceUrl(@id)}"><xsl:value-of select="@nodeName" /></a></h3>
<xsl:apply-templates select="dato" mode="date" />
<p>
<a href="{umbraco.library:NiceUrl(@id)}"><xsl:value-of select="teaser"/></a>
</p>
</li>
</xsl:template>
<!-- Format all dates here -->
<xsl:template match="* | @*" mode="date">
<!-- Format the date any way you want here... -->
<xsl:value-of select="umbraco.library:FormatDateTime(., 'd. MMMM, yyyy')" />
</xsl:template>
</xsl:stylesheet>
sorting and grouping sub nodes
Im trying to sort the sub nodes of a page by date, and the grouping them in sets of 3 wrapped in a div.
I've got the grouping to work, but im at a bit of a loss as how to get the nodes sorted correctly...
i would like to sort by the parameter "dato"
Any help appriciated :)
<xsl:for-each select="$currentPage/* [@isDoc and string(umbracoNaviHide) != '1'][position() mod 3 = 1]">
<div>
<ul>
<xsl:for-each select=".|following-sibling::*[position() < 3]">
<li>
<h3><a href="{umbraco.library:NiceUrl(@id)}"><xsl:value-of select="@nodeName"/></a></h3>
<xsl:value-of select="umbraco.library:FormatDateTime(dato, 'd. MMMM, yyyy')"/>
<p><a href="{umbraco.library:NiceUrl(@id)}"><xsl:value-of select="teaser"/></a></p>
</li>
</xsl:for-each>
</ul>
</div>
</xsl:for-each>
Hi Claus,
Have you found a solution to your question. Or do you still work on finding a solution to it?
/Dennis
No, i'm stuck and hoping for help now that Codegarden is over.
But im starting to get pressed for time, as im presenting the solution on monday, so i might have to think of another solution.
Any help anyone?
Isnt it just a <xsl:sort select="./date" data-type="number" order="descending" />
If the date field in the data is not a number try and parse it to a number with some string format within the umbraco library
Hi Claus,
The trick is that you need to build a sorted version of the nodes because the following-sibling:: axis (and other axes) always works in document order. Here's something to work from:
/Chriztian
@Chriztian Please dont ever ever ever leave the Umbraco community.
As always you rock so hard!!!
Thanks - very nice end-of-day high-five :)
/Chriztian
Solved my sorting to...
Yes he does rock!...
is working on a reply...