Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Claushingebjerg 939 posts 2574 karma points
    Jun 14, 2011 @ 22:04
    Claushingebjerg
    0

    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() &lt; 3]">
    <li>
    <h3><href="{umbraco.library:NiceUrl(@id)}"><xsl:value-of select="@nodeName"/></a></h3>
         <xsl:value-of select="umbraco.library:FormatDateTime(dato, 'd. MMMM, yyyy')"/>
         <p><href="{umbraco.library:NiceUrl(@id)}"><xsl:value-of select="teaser"/></a></p>    
           </li>
         </xsl:for-each>
      </ul>
      </div>
    </xsl:for-each>
  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Jun 22, 2011 @ 00:02
    Dennis Aaen
    0

    Hi Claus,

    Have you found a solution to your question. Or do you still work on finding a solution to it?

    /Dennis

  • Claushingebjerg 939 posts 2574 karma points
    Jun 22, 2011 @ 08:21
    Claushingebjerg
    0

    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?

  • Anders Burla 2560 posts 8256 karma points
    Jun 22, 2011 @ 09:10
    Anders Burla
    0

    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

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Jun 22, 2011 @ 17:47
    Chriztian Steinmeier
    1

    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:

    <?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() &lt; $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>
    

    /Chriztian

  • Claushingebjerg 939 posts 2574 karma points
    Jun 23, 2011 @ 15:03
    Claushingebjerg
    0

    @Chriztian Please dont ever ever ever leave the Umbraco community.

    As always you rock so hard!!!

     

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Jun 23, 2011 @ 15:17
    Chriztian Steinmeier
    0

    Thanks - very nice end-of-day high-five :)

    /Chriztian

  • Bent Holz 100 posts 273 karma points
    Mar 14, 2012 @ 09:17
    Bent Holz
    0

    Solved my sorting to...

    Yes he does rock!...   

Please Sign in or register to post replies

Write your reply to:

Draft