Copied to clipboard

Flag this post as spam?

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


  • Eddie Foreman 215 posts 288 karma points
    Oct 19, 2013 @ 23:57
    Eddie Foreman
    0

    Help with sub menu

    Hi All,

    Been working on the following xslt for Umbraco 4.11.10

    <?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:Exslt.Tags="urn:Exslt.Tags" xmlns:eddieforeman.umbraco="urn:eddieforeman.umbraco"
    exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets Exslt.Tags eddieforeman.umbraco ">


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

    <xsl:param name="currentPage"/>


    <!-- Level that subnav starts at -->
    <xsl:variable name="level" select="2"/>

    <!-- Max level of subnav -->
    <xsl:variable name="maxLevelForSubNav" select="4" />
    <xsl:variable name="excludeDocumentTypes" select="',Settings,ErrorPages,NewsArticle,OfficeLocation,ContactDetails,TeamProfile,Tombstone,Vacancy,Quatation,GoogleMapManagerMarker,FAQ,TabItem,Testimonial,'"/>

    <xsl:variable name="newline"><xsl:text>&#10;</xsl:text></xsl:variable>

    <xsl:template match="/">

    <xsl:if test="name($currentPage/parent:: *[@isDoc]) != 'ErrorPages'">
    <div class="sub-nav">&nbsp;
    <xsl:choose>
    <xsl:when test="name($currentPage/parent::* [@isDoc]) = 'Home' and count($currentPage/* [@isDoc]) = 0">
    <xsl:call-template name="drawNodes">
    <xsl:with-param name="parent" select="$currentPage/ancestor-or-self::* [@level = 2][@isDoc and @level &gt; 1][@isDoc and @level &lt;= $maxLevelForSubNav and not(contains($excludeDocumentTypes, concat(',', name() ,','))) ]" />
    </xsl:call-template>
    </xsl:when>
    <xsl:otherwise>
    <xsl:call-template name="drawNodes">
    <xsl:with-param name="parent" select="$currentPage/ancestor-or-self::* [@level = 2][@isDoc]/* [@isDoc and @level &lt;= $maxLevelForSubNav and not(contains($excludeDocumentTypes, concat(',', name() ,','))) ]" />
    </xsl:call-template>
    </xsl:otherwise>
    </xsl:choose>
    </div>
    </xsl:if>

    </xsl:template>

    <xsl:template name="drawNodes">
    <xsl:param name="parent" />
    <!-- only show 4th level subpages when the current page or ancestor is the parent
    <xsl:if test="$currentPage/ancestor-or-self::*/@id = $parent/@id"> -->
    <xsl:variable name="nodes" select="$parent" />
    <xsl:if test="count($nodes) > 0">

    <xsl:value-of select="$newline"/>
    <ul>
    <xsl:value-of select="$newline"/>
    <xsl:for-each select="$nodes">
    <li>
    <a href="{umbraco.library:NiceUrl(@id)}">
    <xsl:value-of select="@nodeName"/>
    </a>
    <!-- check for child nodes -->
    <xsl:if test="count(./* [@isDoc and @level &lt;= $maxLevelForSubNav and not(contains($excludeDocumentTypes, concat(',', name() ,',')))]) &gt; 0">
    <xsl:call-template name="drawNodes">
    <xsl:with-param name="parent" select="./* [@isDoc and @level &lt;= $maxLevelForSubNav and not(contains($excludeDocumentTypes, concat(',', name() ,','))) ]"/>
    </xsl:call-template>
    </xsl:if>
    </li>
    <xsl:value-of select="$newline"/>
    </xsl:for-each>
    </ul>
    <xsl:value-of select="$newline"/>
    </xsl:if>
    <!--</xsl:if>-->
    </xsl:template>

    </xsl:stylesheet>

    The menu lists all of the sub pages of a section. I would like to only show the 4th level sub pages when the current page or ancestor is the parent.  I normally do this with an if statement which I have commented out, as on this occasion it does not produce any menu when used.

    Would be grateful a fresh pair of eyes could take a look at the above xslt

    Thanks,

    Eddie

Please Sign in or register to post replies

Write your reply to:

Draft