Copied to clipboard

Flag this post as spam?

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


  • Ian Pettman 25 posts 53 karma points
    Sep 03, 2013 @ 14:48
    Ian Pettman
    0

    Xslt changing the order of menu items

    I am in the process of editing a website (and am fairly new to this) and one thing that I need to achieve is to change the order that the blog posts display in the drop down menu. At the moment they go in ascending order, with the oldest post being at the top. But I need to change this so that the newest posts displays at the top, on firstly the 'Year' sub-menu, and then the 'Month' sub-menu.

    If anyone could help point me in the right direction it would be a great help.

    The blog is using ublogsy and I am using umbraco 4.11

    Here is a rough example of how the content tree is structured.

    Content

        Home
            Products
            About us
            Support
            Testimonials
            Blog
                2007
                2008
                2009
                2010        
                2011
                2012
                2013
                    2
                        22
                            post    
                    3
                        8
                            post2
                        21
                            post3


    This is the XSLT file that is generating the menu.

    <?xml version="1.0" encoding="utf-8" ?>
    <!DOCTYPE xsl:stylesheet [
            <!ENTITY nbsp "&#x0A;">
    ]>
    <xsl:stylesheet
      version="1.0"
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
      xmlns:msxml="urn:schemas-microsoft-com:xslt"
      xmlns:umbraco.library="urn:umbraco.library"
      exclude-result-prefixes="msxml umbraco.library">

            <xsl:output method="xml" indent="yes" omit-xml-declaration="yes" />

            <xsl:param name="currentPage" />
            <xsl:variable name="level" select="1" />
            
            <xsl:variable name="navRoot" select="$currentPage/ancestor-or-self::*[@level = $level][not(umbracoNaviHide = 1)]" />
            <xsl:variable name="navRootItems" select="$navRoot/*[@isDoc][not(umbracoNaviHide = 1)]" />

            <xsl:template match="/">
                <a title="Show navigation" href="#nav">Show navigation</a>
                <a title="Hide navigation" href="#">Hide navigation</a>      

                <div id="navlogo"><a title="HOME" href="/home.aspx">  
                <span style="position:absolute;width:100%;height:100%;top:0;left: 0;"></span>
                </a></div>           

                      <ul class="clearfix">
                        <li>
                          <xsl:if test="$currentPage/@nodeName = 'Home'"><xsl:attribute name="class">current</xsl:attribute></xsl:if>
                          <a href="/">Home</a>
                        </li>
                      

                      <xsl:if test="$navRootItems">

                          <xsl:apply-templates select="$navRootItems" />

                      </xsl:if>
                        <div id="menuspace"/>
                      </ul>

         
            </xsl:template>

            <xsl:template match="*[@isDoc]">


              
              <li>
                <xsl:if test="@id = $currentPage/@id"><xsl:attribute name="class">current</xsl:attribute></xsl:if>
                <a>
                  <xsl:attribute name="href">
                    <xsl:value-of select="umbraco.library:NiceUrl(@id)" />
                  </xsl:attribute>
                  <xsl:choose>
                    <xsl:when test="@level = 4 and (self::uBlogsyFolderMonth | self::umbracoBlogDateFolder | self::DateFolder)">
                      <xsl:value-of select="umbraco.library:FormatDateTime(@createDate, 'MMMM')" />
                    </xsl:when>
                    <xsl:otherwise>
                      <xsl:apply-templates select="@nodeName" />
                    </xsl:otherwise>
                  </xsl:choose>
                </a>
                <xsl:if test="*[@isDoc][not(umbracoNaviHide = 1)][not((self::uBlogsyFolderMonth | self::umbracoBlogDateFolder | self::DateFolder)[@level = 5])]">
                  <ul>
                    <xsl:apply-templates select="*[@isDoc][not(umbracoNaviHide = 1)][not((self::uBlogsyFolderMonth | self::umbracoBlogDateFolder | self::DateFolder)[@level = 5])]" />
                  </ul>
                </xsl:if>
              </li>

            </xsl:template>
            
            <xsl:template match="@nodeName[string-length() &gt; 25]">
              <xsl:attribute name="title">
                <xsl:value-of select="." />
              </xsl:attribute>
              <xsl:value-of select="concat(substring(., 1, 24), '&#8230;')" />
            </xsl:template>
     
    </xsl:stylesheet>


    Thanks

  • Kasper Dyrvig 246 posts 379 karma points
    Sep 16, 2013 @ 19:10
    Kasper Dyrvig
    0

    Hi Ian,

    I'm not that experienced with ublogsy. BUT you can try experimenting with this:

    <xsl:apply-templates select="$navRootItems">
    <xsl:sort select="@createDate" order="descending"/>
    </xsl:apply-templates>

    Hope this can help you...

Please Sign in or register to post replies

Write your reply to:

Draft