Copied to clipboard

Flag this post as spam?

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


  • Tom Cowling 144 posts 343 karma points
    Jul 19, 2010 @ 16:13
    Tom Cowling
    0

    Multi-level menu system

    Hi everyone,

    I've searched the forums high and low and can't seem to find the answer I'm looking for, so if anyone can help it would be much appreciated. :)

    Background:
    What I currently have is a multi level site. I have included a picture of the site structure in case I get mixed up with any of my node levels. I also have NO experience of XSLT at all.

    I have a menu at the top which shows level 2 nodes (About, Research, Learning & Teaching etc.). This menu is static as I may not want to show everything at level 2 and thought it best to plan ahead.

    Down the left hand side I want a second navigation so that If I browse to the About section, I get a menu with all the level 3 nodes. This I can achieve, but the problem I have is that the site goes a level deeper than this and I want it so that when you click on say Company Structure, it expands to show the child nodes under that one (level 4).

     

    To illustrate the above example:

    +Contact Us
    +History
    +News and Media
    +Governance
    +Company Structure
       -Subsidiary Companies
       -General Information

     

    I've included XSLT code so far in the next post.

    Thanks a lot for help in advance,

     

    Tom

  • Tom Cowling 144 posts 343 karma points
    Jul 19, 2010 @ 16:13
    Tom Cowling
    0
    <?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:ps="urn:percipientstudios-com:xslt"
        exclude-result-prefixes="msxml umbraco.library ps">
    <xsl:output method="xml" omit-xml-declaration="yes" />

    <!--
    ======================================================================
    NavigationHierarchy.xslt
    ======================================================================
    Copyright 2008 Percipient Studios. All rights reserved.
    www.percipientstudios.com
    ======================================================================
    -->

    <!-- ============================================================ -->
    <xsl:param name="currentPage"/>

    <xsl:variable name="startingLevel">
        <!-- what level in the content tree is the "top" of the navigation list generated? -->
        <xsl:choose>
            <xsl:when test="string(/macro/startingLevel) != ''">
                <xsl:value-of select="/macro/startingLevel"/>
            </xsl:when>
            <xsl:otherwise>2</xsl:otherwise>
        </xsl:choose>
    </xsl:variable>

    <xsl:variable name="stoppingLevel">
        <!-- what level in the content tree is the lowest you want to display? -->
        <xsl:choose>
            <xsl:when test="string(/macro/stoppingLevel) != ''">
                <xsl:value-of select="/macro/stoppingLevel"/>
            </xsl:when>
            <xsl:otherwise>4</xsl:otherwise>
        </xsl:choose>
    </xsl:variable>

    <xsl:variable name="showHome">
        <!-- show a "Home" link for the top-level node? -->
        <xsl:choose>
            <xsl:when test="string(/macro/showHome) != ''">
                <xsl:value-of select="/macro/showHome"/>
            </xsl:when>
            <xsl:otherwise>0</xsl:otherwise>
        </xsl:choose>
    </xsl:variable>

    <!-- ============================================================ -->

    <xsl:template match="/">
    <div id="sidebar">
    <span class="menuhead">
    <xsl:value-of select="$currentPage/ancestor-or-self::node[@level = '2']/@nodeName"/>
    </span>

    <div id="leftmenu">
        <xsl:if test="$showHome = 1">
            <ul class="Home">
                <li>
                    <xsl:if test="$currentPage/ancestor-or-self::node [@level=$startingLevel]/@id = $currentPage/@id">
                        <xsl:attribute name="class">Current</xsl:attribute>
                    </xsl:if>
                    <a href="/">Home</a>
                </li>
            </ul>
        </xsl:if>

        <xsl:call-template name="drawNodes">
            <xsl:with-param name="parent" select="$currentPage/ancestor-or-self::node/descendant-or-self::node [@level=$startingLevel]" />
        </xsl:call-template>
    </div>
    </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:HasAccess($parent/@id, $parent/@path) = 1)">

            <ul>
                <xsl:attribute name="class">
                    <xsl:text>Level</xsl:text><xsl:value-of select="$parent/node/@level"/>
                </xsl:attribute>
                <xsl:for-each select="$parent/node [string(./data [@alias='umbracoNaviHide']) != '1'
                            and @level &lt;= $stoppingLevel]">
                    <li>
                        <!--<xsl:if test="ps:isInList($currentPage/@path, current()/@id, ',') = 1">-->
            <xsl:if test="$currentPage/ancestor-or-self::node/@id = current()/@id">
                            <xsl:attribute name="class">Current</xsl:attribute>
                        </xsl:if>

                        <xsl:if test="string(data [@alias='umbracoRedirect']) != ''">
                            <a class="ExternalLink" href="{data [@alias='umbracoRedirect']}">
                                <xsl:value-of select="@nodeName" />
                            </a>
                        </xsl:if>
                        <xsl:if test="string(data [@alias='umbracoRedirect']) = ''">
           
                            <a href="{umbraco.library:NiceUrl(@id)}">
                                <xsl:value-of select="@nodeName" />
                            </a>
                        </xsl:if>

                        <xsl:if test="count(./node [string(./data [
                            @alias='umbracoNaviHide']) != '1'
                            and @level &lt;= $stoppingLevel
                            and ps:isInList($currentPage/@path, current()/@id, ',') = 1
                            ]) &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>
    <!-- ============================================================ -->

    <msxml:script language="C#" implements-prefix="ps">
    <![CDATA[
    public bool isInList(string sList, string sFind, string sDelim) {
        foreach (string sItem in sList.Split(sDelim.ToCharArray()[0]))
            if (sItem == sFind)
                return true;

        return false;
    }
    ]]>
    </msxml:script>

    <!-- ============================================================ -->

    </xsl:stylesheet>
  • lukac 1 post 21 karma points
    Sep 16, 2010 @ 14:34
    lukac
    0

    save xlst file >>> Error occured

    System.OverflowException: Value was either too large or too small for an Int32.
    at System.Convert.ToInt32(Double value)
    at System.Double.System.IConvertible.ToInt32(IFormatProvider provider)
    at System.Convert.ChangeType(Object value, Type conversionType, IFormatProvider provider)
    at System.Xml.Xsl.Runtime.XmlQueryRuntime.ChangeTypeXsltArgument(XmlQueryType xmlType, Object value, Type destinationType)
    at System.Xml.Xsl.Runtime.XmlQueryContext.InvokeXsltLateBoundFunction(String name, String namespaceUri, IList`1[] args)
    at (XmlQueryRuntime {urn:schemas-microsoft-com:xslt-debug}runtime, IList`1 parent)
    at (XmlQueryRuntime {urn:schemas-microsoft-com:xslt-debug}runtime)
    at Root(XmlQueryRuntime {urn:schemas-microsoft-com:xslt-debug}runtime)
    at Execute(XmlQueryRuntime {urn:schemas-microsoft-com:xslt-debug}runtime)
    at System.Xml.Xsl.XmlILCommand.Execute(Object defaultDocument, XmlResolver dataSources, XsltArgumentList argumentList, XmlSequenceWriter results)
    at System.Xml.Xsl.XmlILCommand.Execute(Object defaultDocument, XmlResolver dataSources, XsltArgumentList argumentList, XmlWriter writer, Boolean closeWriter)
    at System.Xml.Xsl.XmlILCommand.Execute(IXPathNavigable contextDocument, XmlResolver dataSources, XsltArgumentList argumentList, XmlWriter results)
    at System.Xml.Xsl.XmlILCommand.Execute(IXPathNavigable contextDocument, XmlResolver dataSources, XsltArgumentList argumentList, TextWriter results)
    at System.Xml.Xsl.XslCompiledTransform.Transform(IXPathNavigable input, XsltArgumentList arguments, TextWriter results)
    at umbraco.presentation.webservices.codeEditorSave.SaveXslt(String fileName, String oldName, String fileContents, Boolean ignoreDebugging)

  • Rich Green 2246 posts 4008 karma points
    Sep 16, 2010 @ 14:50
Please Sign in or register to post replies

Write your reply to:

Draft