Copied to clipboard

Flag this post as spam?

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


  • Kevin Walker 66 posts 87 karma points
    Apr 15, 2011 @ 12:22
    Kevin Walker
    0

    Sub Navigation

    I have sub navigation within my site that displays all nav from levels 2 / 3 / 4 however the current XSLT I am using, which has been applied from another post on this forum, displays all nodes open. I need this to only show the descendants of the current node we are on. Here is my XSLT:

    <?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"
      exclude-result-prefixes="msxml umbraco.library">
    
      <xsl:output method="xml" omit-xml-declaration="yes"/>
    
      <xsl:param name="currentPage"/>
    
      <xsl:variable name="parentNode" select="$currentPage/ancestor-or-self::*[@isDoc and @level = 2]"/>
    
      <xsl:template match="/">
        <!-- Level 2 -->
        <h1>
          <a href="{umbraco.library:NiceUrl($parentNode/@id)}">
            <xsl:value-of select="$parentNode/@nodeName"/>
          </a>
        </h1>
    
        <!--Level 3-->
        <xsl:if test="count($parentNode/*[@isDoc and string(umbracoNaviHide)!='1']) &gt; 0">
          <ul id="secondary-navigation">
            <xsl:for-each select="$parentNode/*[@isDoc and string(umbracoNaviHide)!='1']">
              <li>
                <a href="{umbraco.library:NiceUrl(@id)}">
                 <xsl:value-of select="@nodeName"/>
                </a>
    
                <!--Level 4-->
                <xsl:if test="count(*[@isDoc and string(umbracoNaviHide)!='1']) &gt; 0">
                  <ul class="subnav">
                    <xsl:for-each select="*[@isDoc and string(umbracoNaviHide)!='1']">
                      <li>
                        <a href="{umbraco.library:NiceUrl(@id)}">
                          <xsl:value-of select="@nodeName"/>
                        </a>
                      </li>
                    </xsl:for-each>
                  </ul>
                </xsl:if>
              </li>
            </xsl:for-each>
          </ul>
        </xsl:if>
    
      </xsl:template>
    
    </xsl:stylesheet>

    This displays as follows (apologies for the black lines - confidentiality and all that) but it gives an idea. I iodally just need to show one of these sections at a time. i.e When you click the node named 'Testing' then the other two nodes with arrows on them would not be expanded but the 'Testing' node and all of its children would be expanded. Any help greatly appreciated.

     

  • Pasang Tamang 258 posts 458 karma points
    Apr 15, 2011 @ 12:49
    Pasang Tamang
    0

    Hi

    If the problem is only of expanding the menu then I personally recommend you jquery. Jquery provide such a functionality of toggling the menus. Here is one example http://www.sohtanaka.com/web-design/examples/toggle/

    Hope this helps you

    Pnima

  • praveity 100 posts 125 karma points
    May 04, 2011 @ 06:26
    praveity
    0

    Go with Pnima, jquery is really what you need.

    There is a jquery plugin with name jquery.droppy. Use that one.

  • Sean Holmesby 61 posts 82 karma points
    May 05, 2011 @ 04:34
    Sean Holmesby
    0

    jQuery is great to dynamically do this, but it means the markup is still on the page, just hidden from the user's view.

    To only have your markup output what you want to see on the page you should put a test around the group you want to show.

    You should test if the current node in the loop is an ancestor or actually is the page you are on is. In your example, when the loop gets to the 'Testing' node, it'll test if you're on the Testing page, or a child of the Testing page, and if so, enter the next section to show the descendants.

    I think level 3 is where you want to do the test in the example you give.

    so

    <xsl:if test="count($parentNode/*[@isDoc and string(umbracoNaviHide)!='1']) &gt; 0">

    becomes (untested - sorry)

    <xsl:if test="$currentPage/@id = ./ancestor-or-self::*/@id">

    <xsl:if test="count($parentNode/*[@isDoc and string(umbracoNaviHide)!='1']) &gt; 0">

     

    Sorry, I don't have the ability to test this at the moment, but I'm pretty sure it should work.

    - Sean

     

Please Sign in or register to post replies

Write your reply to:

Draft