Copied to clipboard

Flag this post as spam?

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


  • Sune Jepsen 25 posts 109 karma points
    Dec 16, 2010 @ 13:37
    Sune Jepsen
    0

    multi level menu

     Im working on a multi level menu on Umbraco version: umbraco v 4.5.2 (Assembly version: 1.0.3891.20719)

    My goal is this structure:

    -menu item1
    -menu item2
    -menu item3
       -menu item3.1
       -menu item3.2
    -menu item4
    -menu item5
       -menu item5.1
       -menu item5.2
    -menu item6

    Initially all child nodes would be collapsed, but if you hit the parent menu item (fx menu item3 or menu item5).  the underlying childmenu should be visible. The same apply when you hit a child menu item (fx menu item3.1) the structure for that childmenu should be visible. Its important to note that menu item3 and menu item5 etc which has child menu are actually pages with content on, so no hashes on theses notes, they have links to pages.

    Ive done a lot searching to find something that could fit into my solution. And here the 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" 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"
      exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets ">


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

           <xsl:param name="currentPage"/>
            <xsl:variable name="siteRoot" select="$currentPage/ancestor-or-self::*[@level = 1]" />
           
            <xsl:template match="/">
                    <ul>
                        <xsl:apply-templates select="$siteRoot/*[@isDoc]" />
                    </ul>
            </xsl:template>
           
            <xsl:template match="*[@isDoc]">
                    <li>
                        <a href="{umbraco.library:NiceUrl(@id)}">
                             <xsl:value-of select="@nodeName" />
                        </a>
                       
                        <xsl:if test="*[@isDoc][not(umbracoNaviHide = 1)]">
                             
                               <ul class="hide">
                                 <xsl:if test="@id=$currentPage/@id or $currentPage/@level = 3 ">
                                
                                      <xsl:attribute name="class">show</xsl:attribute>
                                    </xsl:if>
                                    <xsl:apply-templates select="*[@isDoc]" />
                                </ul>
                        </xsl:if>
                    </li>
            </xsl:template>
           
            <xsl:template match="*[umbracoNaviHide = 1]" />

    </xsl:stylesheet>

    But the problem here is when I hit a given child menu item, all parent notes which has child menus are going to be visible. So I am open for some solutions which can solve my problem.

     

     

  • Thijs Kuipers 43 posts 66 karma points
    Dec 16, 2010 @ 16:02
    Thijs Kuipers
    0

    I've made something similar for http://www.pijn.com e.g. http://www.pijn.com/nl/patienten/oorzaak-pijn/diagnoses-per-regio/knie--enkel--voet

    It's in the legacy schema, but you'll be able to get the gist of it (I guess):

     

    <?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:template match="/">
    
            <!-- The fun starts here -->
            <xsl:variable name="subMenuTopLevelNodes" select="$currentPage/ancestor-or-self::node[@level = 4]/node [string(data[@alias = 'umbracoNaviHide']) != '1']"/>
            <xsl:if test="count($subMenuTopLevelNodes) &gt; 0">
                <div id="submenu">
                    <ul class="submenuList">
                        <xsl:call-template name="submenuTree">
                            <xsl:with-param name="pageNodes" select="$subMenuTopLevelNodes"/>
                        </xsl:call-template>
                    </ul>
                </div> <!-- end submenu -->
            </xsl:if>
        </xsl:template>
    
        <xsl:template name="submenuTree">
            <xsl:param name="pageNodes"/>
            <xsl:for-each select="$pageNodes">
                <li>
                    <a href="{umbraco.library:NiceUrl(@id)}">
                        <xsl:choose>
                            <xsl:when test="count(current()/node) &gt; 0">
                                <xsl:choose>
                                    <xsl:when test="$currentPage/@level &gt;= current()/@level and @id = $currentPage/ancestor-or-self::node[@level=current()/@level]/@id">
                                        <xsl:attribute name="class">show-children</xsl:attribute>
                                        <xsl:if test="$currentPage/@id = @id">
                                            <xsl:attribute name="class">show-children selected</xsl:attribute>
                                        </xsl:if>
                                    </xsl:when>
                                    <xsl:otherwise>
                                        <xsl:attribute name="class">has-children</xsl:attribute>
                                        <xsl:if test="$currentPage/@id = @id">
                                            <xsl:attribute name="class">has-children selected</xsl:attribute>
                                        </xsl:if>
                                    </xsl:otherwise>
                                </xsl:choose>
                            </xsl:when>
                            <xsl:otherwise>
                                <xsl:if test="$currentPage/@id = @id">
                                    <xsl:attribute name="class">selected</xsl:attribute>
                                </xsl:if>
                            </xsl:otherwise>
                        </xsl:choose>
                        <xsl:value-of select="@nodeName"/>
                    </a>
                    <xsl:if test="$currentPage/@level &gt;= current()/@level and @id = $currentPage/ancestor-or-self::node[@level = current()/@level]/@id and count(current()/node) &gt; 0">
                        <ul>
                            <xsl:call-template name="submenuTree">
                                <xsl:with-param name="pageNodes" select="$currentPage/ancestor-or-self::node[@level = current()/@level]/node[string(data[@alias = 'umbracoNaviHide']) != '1']"/>
                            </xsl:call-template>
                        </ul>
                    </xsl:if>
                </li>
            </xsl:for-each>
        </xsl:template>
    </xsl:stylesheet>

     

  • Sune Jepsen 25 posts 109 karma points
    Dec 16, 2010 @ 22:38
    Sune Jepsen
    0

    Thanks for some inspiration, that helped me to get a right solution. My final solution looks like:

    <?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:template match="/">
        <!-- The fun starts here -->
        
        <xsl:variable name="subMenuTopLevelNodes" select="$currentPage/ancestor-or-self::* [@level = 1]/* [string(umbracoNaviHide) != '1' and @isDoc]"/>
        <xsl:if test="count($subMenuTopLevelNodes) &gt; 0">
          <div id="submenu">
            <ul class="submenuList">
              <xsl:call-template name="submenuTree">
                <xsl:with-param name="pageNodes" select="$subMenuTopLevelNodes"/>
              </xsl:call-template>
            </ul>
          </div>
          <!-- end submenu -->
        </xsl:if>
      </xsl:template>
      
      <xsl:template name="submenuTree">
        <xsl:param name="pageNodes"/>
        <xsl:for-each select="$pageNodes">
          <li>
           
            <a href="{umbraco.library:NiceUrl(@id)}">
              <xsl:choose>
                <xsl:when test="count(current()/*[string(umbracoNaviHide) != '1' and @isDoc]) &gt; 0">
                  <xsl:choose>
                    <xsl:when test="$currentPage/@level &gt;= current()/@level and @id = $currentPage/ancestor-or-self::*[@level=current()/@level]/@id">
                      <xsl:attribute name="class">show-children</xsl:attribute>
                      <xsl:if test="$currentPage/@id = @id">
                        <xsl:attribute name="class">show-children selected</xsl:attribute>
                      </xsl:if>
                    </xsl:when>
                    <xsl:otherwise>
                      <xsl:attribute name="class">has-children</xsl:attribute>
                      <xsl:if test="$currentPage/@id = @id">
                        <xsl:attribute name="class">has-children selected</xsl:attribute>
                      </xsl:if>
                    </xsl:otherwise>
                  </xsl:choose>
                </xsl:when>
                <xsl:otherwise>
                  <xsl:if test="$currentPage/@id = @id">
                    <xsl:attribute name="class">selected</xsl:attribute>
                  </xsl:if>
                </xsl:otherwise>
              </xsl:choose>
              <xsl:value-of select="@nodeName"/>
            </a>
             
            <xsl:if test="$currentPage/@level &gt;= current()/@level and @id = $currentPage/ancestor-or-self::*[@level = current()/@level]/@id and count(current()/*[string(umbracoNaviHide) != '1' and @isDoc]) &gt; 0">
              <ul>
                <xsl:call-template name="submenuTree">
                  <xsl:with-param name="pageNodes" select="$currentPage/ancestor-or-self::*[@level = current()/@level]/*[string(umbracoNaviHide) != '1' and @isDoc]"/>
                </xsl:call-template>
              </ul>
            </xsl:if>
          </li>
        </xsl:for-each>
      </xsl:template>
    </xsl:stylesheet>

    you are using "node" but in my version of umbraco I simply cant catch anything with that notation, so ive change it a bit. But does anyone know why I cant get a result with "node"?

  • Eric Herlitz 97 posts 129 karma points
    Feb 10, 2011 @ 20:16
    Eric Herlitz
    0

    Thank you so much for posting this

    I cleaned up the script a bit and changed 

    <xsl:variable name="subMenuTopLevelNodes" select="$currentPage/ancestor-or-self::* [@level = 1]/* [string(umbracoNaviHide) != '1' and @isDoc]"/>

    to

    <xsl:variable name="subMenuTopLevelNodes" select="$currentPage/ancestor-or-self::* [@level = 2]/* [string(umbracoNaviHide) != '2' and @isDoc]"/>

    thus only selecting from the second level since i got my first level in the top menu!

     

    Cheers

  • Max 144 posts 166 karma points
    May 18, 2011 @ 08:07
    Max
    0

    Hello i need some help with the css here:

    i have an <li><a href="/links.aspx" class="selected">Links</a></li> which hs no children so i use this style to change the backgroung image

    #submenu ul.submenuList  li a.selected 
    {
      
     background-image: url(/media/5691/btn_red_arrow.jpg);
     background-repeat:no-repeat;
        

    }

    But if any UL LI element which has child nodes selected also chnages the background colour how can i fix this in css

     

  • Ruel Baybayan 6 posts 26 karma points
    Mar 10, 2012 @ 00:35
    Ruel Baybayan
    0

    Hi,
    UMBRACO 4.711xlst  for multilevel submenu

    Need some help for XLST multilevel submenu but with different class name: Structure as per below:


    - Menu1  class = "current" (if active page)
    --  Menu1.1
    --  Menu1.2class="parent" (nested ul)
    -- Menu 1.2.1 
    -- Menu 1.2.2
    -- Menu 1.2.2  class="parent" (another nested ul)
    -- Menu 1.2.2.1
    -- Menu 1.2.2.2
    - Menu2  class = "current" (if active page)
    --  Menu2.1
    --  Menu2.2class="parent" (nested ul)
    -- Menu 2.2.1 
    -- Menu 2.2.2
    -- Menu 2.2.2  class="parent" (another nested ul)
    -- Menu 2.2.2.1
    -- Menu 2.2.2.2  

     I have managed to get the structure but got stuck on how to impleiment the class name per each list parent. I wanted to have the class inside the attributes as follows:

    <ul class="menu">
    <li><a href="[link]" class="current"><span>Menu1</span></a></li>Note: Active page..set to class="current" 
    <li><a href="[link]" class="parent"><span>Menu2</span></a></li> Note: class="parent" for the next level
    <div><ul>
    <li><a href="[link]"><span>Menu2.1</span></a></li> 
    <li><a href="[link]" class="parent"><span>Menu2.2</span></a></li>  
    <div><ul> 
    <li><a href="[link]"><span>Menu2.2.1</span></a></li> 
    <li><a href="[link]"><span>Menu2.2.2</span></a></li>
       </ul></div> 
    <li><a href="[link]"><span>Menu3.1</span></a></li>  
    </ul></div>
    <li><a href="[link]"><span>Menu1</span></a></li> 
    </ul></div> 

    Below is my xslt code which is working as per the structure but NOT too sure how to impliment the attributes. I had tried Choose but no success.

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

    <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="4"/>

    <xsl:template match="/">
      <div id="menu"><h3><div><ul class="menu"
        <li ><href="#" class="current" ><span>Home</span></a></li>
          <xsl:call-template name="drawNodes">  
              <xsl:with-param name="parent" select="$currentPage/ancestor-or-self::* [@isDoc and @level=1]"/>  
          </xsl:call-template>
       </ul></div></h3></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)">
              
               
                <xsl:for-each select="$parent/* [@isDoc and string(umbracoNaviHide) != '1' and @level &lt;= $maxLevelForSitemap]"
                    <li>  
                         <href="{umbraco.library:NiceUrl(@id)}" class="">
                           <span><xsl:value-of select="@nodeName"/></span>
                         </a>                        
                         <xsl:if test="count(./* [@isDoc and string(umbracoNaviHide) != '1' and @level &lt;= $maxLevelForSitemap]) &gt; 0">   
                              
                              <xsl:call-template name="drawNodes1">    
                                  <xsl:with-param name="parent" select="."/>    
                              </xsl:call-template>  
                         </xsl:if
                    </li>
                  

                </xsl:for-each>

      </xsl:if>
    </xsl:template>

        <xsl:template name="drawNodes1">
      <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)">
      
        <div><ul>           
                <xsl:for-each select="$parent/* [@isDoc and string(umbracoNaviHide) != '1' and @level &lt;= $maxLevelForSitemap]"
                    <li>  
                         <href="{umbraco.library:NiceUrl(@id)}">
                           <span><xsl:value-of select="@nodeName"/></span>
                         </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></div>

      </xsl:if>
    </xsl:template>
        
    </xsl:stylesheet>

     

      

     

     

  • Gary 40 posts 129 karma points
    Jul 09, 2013 @ 13:24
    Gary
    0

    Thank you for this post - it was exactly what i was looking for!!!!!

  • Gary 40 posts 129 karma points
    Jul 10, 2013 @ 10:29
    Gary
    0

    Hey folks, can anyone please help.

    I have a menu like so using the xslt above

    Menu item 1
       sub menu item level 1
           Sub menu item level 2
    Menu item 2
        sub menu item 1
        sub menu item level 2

    My code looks like this

    <xsl:if test="$currentPage/@level &gt;= current()/@level and @id = $currentPage/ancestor-or-self::*[@level = current()/@level]/@id and count(current()/*[string(umbracoNaviHide) != '0' and @isDoc]) &gt; 1">
          <ul class="ssnSubMenuItem">
               <xsl:call-template name="submenuTree">
                  <xsl:with-param name="pageNodes" select="$currentPage/ancestor-or-self::*[@level = current()/@level]/*[string(umbracoNaviHide) != '0' and @isDoc]"/>
               </xsl:call-template>
           </ul>
    </xsl:if>

    I do not want the 'sub menu item level 2' showing in the menu. Can anyone help?

    Thank you for looking!!!

  • Gary 40 posts 129 karma points
    Jul 10, 2013 @ 10:29
    Gary
    0
  • Gary 40 posts 129 karma points
    Jul 10, 2013 @ 10:51
    Gary
    0

    It's ok i fixed it by unchecking 'hide in navi'

Please Sign in or register to post replies

Write your reply to:

Draft