Copied to clipboard

Flag this post as spam?

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


  • Tom Morgan 2 posts 22 karma points
    Oct 20, 2011 @ 08:08
    Tom Morgan
    0

    Menu - Sort by Custom Field

    Hi there,

    I'm trying to modify my menu XSLT to sort by a custom field, called SortOrder, which is defined for each textpage. As you can probably see, it's not much adapted from the original. (full listing below)

    I'm using

    <xsl:sort select="something"/>

    as a basis. Sorting by known nodes, such as name, wors well, so I know that the XML is getting sorted OK.

    The problem is how to reference the custom node. I've tried (without success):

    <xsl:sort select="$currentPage/@SortOrder"/>
    <xsl:sort select="$currentPage/SortOrder"/>
    <xsl:sort select="currentPage()/@SortOrder"/>
    <xsl:sort select="currentPage()/SortOrder"/>
    <xsl:sort select="@SortOrder"/>
    <xsl:sort select="SortOrder"/>  

    I think I'm just missing some syntactically, but I'm not sure what, so any pointers would be much apprechiated.

    Thanks for your time,

    Tom

     

    Full XML listing:

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp "&#x00A0;"> ]>
    <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" xmlns:Exslt.ExsltCommon="urn:Exslt.ExsltCommon" xmlns:Exslt.ExsltDatesAndTimes="urn:Exslt.ExsltDatesAndTimes" xmlns:Exslt.ExsltMath="urn:Exslt.ExsltMath" xmlns:Exslt.ExsltRegularExpressions="urn:Exslt.ExsltRegularExpressions" xmlns:Exslt.ExsltStrings="urn:Exslt.ExsltStrings" xmlns:Exslt.ExsltSets="urn:Exslt.ExsltSets" xmlns:tagsLib="urn:tagsLib" xmlns:BlogLibrary="urn:BlogLibrary"
      exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets tagsLib BlogLibrary ">

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

    <xsl:param name="currentPage"/>

       
    <!-- update this variable on how deep your site map should be -->
    <xsl:variable name="maxLevelForSitemap" select="3"/>
         <xsl:variable name="level" select="1"/>

    <xsl:template match="/">
    <div id="sitemap">
    <xsl:call-template name="drawNodes">  
    <xsl:with-param name="parent" select="$currentPage/ancestor-or-self::* [@isDoc and @level=1]"/>  
    </xsl:call-template>
    </div>
    </xsl:template>

    <xsl:template name="drawNodes">
    <xsl:param name="parent"/>
    <xsl:if test="umbraco.library:IsProtected($parent/@id, $parent/@path) = 0 or (umbraco.library:IsProtected($parent/@id, $parent/@path) = 1 and umbraco.library:IsLoggedOn() = 1)">
    <ul id="suckerfishnav" class="sf-menu">
      
      <li class="home">
             <xsl:if test="$currentPage/@id = $currentPage/ancestor-or-self::* [@level=$level]/@id">
                 <xsl:attribute name="class">home current</xsl:attribute>
             </xsl:if>
             <a href="/">Home</a>
           </li>
      
      <xsl:for-each select="$parent/* [@isDoc and string(umbracoNaviHide) != '1' and @level &lt;= $maxLevelForSitemap]">
    <xsl:sort select="$currentPage/@SortOrder"/>
      <li>  
      <xsl:if test="@id = $currentPage/@id">
            <xsl:attribute name="class">current</xsl:attribute>
          </xsl:if>
    <a href="{umbraco.library:NiceUrl(@id)}">
    <xsl:value-of select="@nodeName"/></a>  
    <xsl:if test="count(./* [@isDoc and string(umbracoNaviHide) != '1' and @level &lt;= $maxLevelForSitemap]) &gt; 0">   
    <xsl:call-template name="drawNodes">    
    <xsl:with-param name="parent" select="."/>    
    </xsl:call-template>  
    </xsl:if>
    </li>
    </xsl:for-each>
    </ul>
    </xsl:if>
    </xsl:template>
    </xsl:stylesheet>
  • Dirk De Grave 4537 posts 6006 karma points MVP 3x admin c-trib
    Oct 20, 2011 @ 09:06
    Dirk De Grave
    1

    Can you try:

    <xsl:sort select="./SortOrder" data-type="number"/>

     

    Hope this helps.

    Regards,

    /Dirk

     

  • Chriztian Steinmeier 2726 posts 8320 karma points MVP 4x admin c-trib
    Oct 21, 2011 @ 00:32
    Chriztian Steinmeier
    0

    Hi Tom,

    If your custom field is named "SortOrder" that's exactly what you should use (which is the last one you mention yourself) - however, convention is (and the UI will try to enforce this) to lowercase the first character for properties, so you should definitely check that the XML element is actually <SortOrder> and not <sortOrder>.

    It's important not to include $currentPage here, because the XPath will be evaluated relative to the node being processed, so adding $currentPage will yield the same value for every node, thus not changing the sort order.

    So Dirks example is what should actually work (you can omit the "./" though - doesn't change anything).

    /Chriztian

  • Tom Morgan 2 posts 22 karma points
    Oct 21, 2011 @ 09:56
    Tom Morgan
    0

    Hi there,

     

    Neither of those things work I'm afraid.

    Is there an easy way of just getting out the XML at all - that way I can see firstly that the sort order field is included, and secondly, can make a better stab at the XPath!

    -tom

  • Chriztian Steinmeier 2726 posts 8320 karma points MVP 4x admin c-trib
    Oct 22, 2011 @ 01:09
    Chriztian Steinmeier
    0

    Hi Tom,

    *Ahem* - there's actually a package for that - look for "XMLDump"...

    Alternatively, you can do <textarea><xsl:copy-of select="$currentPage/ancestor-or-self::root" /></textarea> somewhere, and you'll get a dump of the XML.

    /Chriztian

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies