Copied to clipboard

Flag this post as spam?

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


  • Fuji Kusaka 2203 posts 4220 karma points
    Feb 28, 2011 @ 13:26
    Fuji Kusaka
    0

    Top Navigation with Drop Down Menu

    Can someone help me out with Drop Down Menu on Hover effect.

    I have a top Navigation which i previously created in dreamweaver with the followin structure:

     <ul id="top-navigation">
        <li><a href="#">HOME</a></li>
        <li><a href="#">ABOUT US</a>    
            <ul>
                <li><a href="#">ASSOCIATION BACKGROUND</a></li>
                <li><a href="#">MISSION &amp; OBJECTIVE</a></li>
                <li><a href="#">MANAGEMENT COMMITTEE</a></li>
                <li><a href="#">CSR MANAGEMENT</a></li>
                <li><a href="#">ABOUT MAURITIUS</a></li>
                <li><a href="#">LINKS</a></li>
            </ul>    
        </li>
        
        <li><a href="#">SCHOOL</a>    
            <ul>
                <li><a href="#">THE PRIMARY SCHOOL (CHALLENGES)</a></li>
                <li><a href="#">THE PROGRAMME</a></li>
                <li><a href="#">TEACHING STAFF</a></li>
                <li><a href="#l">LEARNING DISABILITIES</a></li>
                <li><a href="#">PARA-MEDICAL SUPPORT</a></li>
                <li><a href="#">EXTRA-CURRICULUM ACTIVITIES</a></li>
            </ul>
        </li>
        
        <li><a href="#">YOUNG ADULT CLASS</a></li>
        <li><a href="#">AUTISM</a></li>
        <li><a href="#">PARENT'S CORNER</a></li>
        <li><a href="#">KID'S CORNER</a></li>
        <li><a href="#">CONTACT</a></li>
    </ul>

    This works perfectly with my css and the Hover effect as well but since am using umbraco i wanted to create it as an XSLT file but i cant get the second level navigation that is the Drop Down Menu:

    Here is how i structured it in XSLT:

    <xsl:variable name="level" select="1"/>
    <xsl:variable name="dropDown" select="2"/>
        
        
    <xsl:template match="/">

    <!-- The fun starts here -->
    <ul id="anougrandi-menu-top">
    <xsl:for-each select="$currentPage/ancestor-or-self::* [@level=$level]/* [@isDoc and string(umbracoNaviHide) != '1']">
      <li>
        <a href="{umbraco.library:NiceUrl(@id)}"><xsl:value-of select="@nodeName"/></a>   
         
           <ul> 
            <xsl:for-each select="$currentPage/ancestor-or-self::* [@level=$dropDown]/* [@isDoc and string(umbracoNaviHide) != '2']"> 
              <li><a href="{umbraco.library:NiceUrl(@id)}"><xsl:value-of select="@nodeName"/></a></li> 
           </xsl:for-each>         
          </ul>      
        
        
      </li>
    </xsl:for-each>
    </ul>

     

    Can someone help me out??

     

    Fuji


  • Kim Andersen 1447 posts 2197 karma points MVP
    Feb 28, 2011 @ 18:54
    Kim Andersen
    0

    Hi Fuji.

    Could you try changing this:

    <ul> 
            <xsl:for-each select="$currentPage/ancestor-or-self::* [@level=$dropDown]/* [@isDoc and string(umbracoNaviHide) != '2']"> 
              <li><a href="{umbraco.library:NiceUrl(@id)}"><xsl:value-of select="@nodeName"/></a></li> 
           </xsl:for-each>         
          </ul>

    to this:

    <xsl:if test="count(./* [@isDoc and string(umbracoNaviHide) != '1']) &gt; 0">     
    <ul>
    <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>

    Does this render the second level nodes under the right parent nodes?

    /Kim A

  • Fuji Kusaka 2203 posts 4220 karma points
    Feb 28, 2011 @ 19:04
    Fuji Kusaka
    0

    Hi Kim,

     

    I got it working.....

     

     

    /fuji

  • Kim Andersen 1447 posts 2197 karma points MVP
    Mar 01, 2011 @ 08:04
    Kim Andersen
    0

    Great to hear Fuji :)

    /Kim A

  • Fuji Kusaka 2203 posts 4220 karma points
    Mar 01, 2011 @ 15:10
    Fuji Kusaka
    0

    Kim can you help me sort this out please

    The Drop Down Menu works fine and when i click on one of the Links on top it returns a class to indicate this is the active Link but now am trying to get the same result but when clicking on the child node.

    The parent node should be the active one.

    Here is my code

     

    <ul id="top-navigation">
     

      <li>
           <xsl:attribute name="class">
             <xsl:if test="$currentPage/@level=$level">
              <xsl:text>current</xsl:text>
              </xsl:if>
         </xsl:attribute>
          <a href="/">     
             <xsl:value-of select="$currentPage/ancestor-or-self::*/@nodeName"/>
          </a>  
     </li>
      
      <xsl:for-each select="$currentPage/ancestor-or-self::* [@level=$level]/* [@isDoc and string(umbracoNaviHide) != '1']">  
      <li>
         <xsl:attribute name="class">
             <xsl:if test="$currentPage/@id=@id">
              <xsl:text>current</xsl:text>
              </xsl:if>
         </xsl:attribute>
        
        
        <a href="{umbraco.library:NiceUrl(@id)}"><xsl:value-of select="@nodeName"/></a>    
        <!-- Drop Down Menu -->
        <xsl:if test="count(./* [@isDoc and string(umbracoNaviHide) != '1']) &gt; 0">
           <ul>
             <xsl:for-each select="./* [@isDoc and string(umbracoNaviHide) != '1']">
                 <li>
                   
                    <xsl:attribute name="class">
                       <xsl:if test="$currentPage/descendant::* [@level=1]">                    
                        <xsl:text>current</xsl:text>
                      </xsl:if>
                    </xsl:attribute>
                   
                   <a href="{umbraco.library:NiceUrl(@id)}"><xsl:value-of select="@nodeName"/></a></li>
             </xsl:for-each>
           </ul>
        </xsl:if>
        <!-- End of Drop Down Menu -->
        
      </li>
      </xsl:for-each>
      
    </ul>

     


  • Kim Andersen 1447 posts 2197 karma points MVP
    Mar 01, 2011 @ 15:24
    Kim Andersen
    0

    Hi Fuji

    Try changing this:

    <xsl:attribute name="class">
           <xsl:if test="$currentPage/descendant::* [@level=1]">                   
                <xsl:text>current</xsl:text>
           </xsl:if>
    </xsl:attribute>

    To this:

    <xsl:if test="$currentPage/ancestor-or-self::node/@id = current()/@id">
    <xsl:attribute name="class">current</xsl:attribute>
    </xsl:if>

    /Kim A

  • Kim Andersen 1447 posts 2197 karma points MVP
    Mar 01, 2011 @ 15:27
    Kim Andersen
    0

    And you might want to change this for the parent node as well. You can do by changing this:

    <xsl:attribute name="class">
    <xsl:if test="$currentPage/@id=@id">
    <xsl:text>current</xsl:text>
    </xsl:if>
    </xsl:attribute>

    inside the for-each loop, to this:

    <xsl:if test="$currentPage/ancestor-or-self::node/@id = current()/@id">
         
    <xsl:attribute name="class">current</xsl:attribute>
    </xsl:if>

    /Kim A

  • Kim Andersen 1447 posts 2197 karma points MVP
    Mar 01, 2011 @ 15:30
    Kim Andersen
    0

    Doh!

    The above code I wrote to you was to the legacy schema. Try this instead:

    <xsl:if test="$currentPage/ancestor-or-self::*[@isDoc]/@id = current()/@id">
           
    <xsl:attribute name="class">current</xsl:attribute>
    </xsl:if>

    The difference is the node that has been changed to *[@isDoc]

    /Kim A

  • Fuji Kusaka 2203 posts 4220 karma points
    Mar 01, 2011 @ 16:44
    Fuji Kusaka
    0

    Nope still not working....the parent still not being highlighted....when i view the source code its still the child node which contains the class="current".

     

    In my case my top navigation is 

    Accueil 

    Informations

    • - Information 1
    • - Information 2

    Produits

    Formation

    Contact

    So when i click on Informations main page the Link on top of my menu is Highlighted when if i click on Information 1 my parent Informations is not Hightlighted.

     

    /Fuji

  • Fuji Kusaka 2203 posts 4220 karma points
    Mar 01, 2011 @ 16:49
    Fuji Kusaka
    0

    Kim i got it working!!!....Great ...... one of my classes was missing!!

     

    Thanks a bunch....

     

    /fuji

  • Kim Andersen 1447 posts 2197 karma points MVP
    Mar 01, 2011 @ 16:58
    Kim Andersen
    0

    Thats good to hear Fuji. Could you show us the code that solved the problem?

    /Kim A

  • Fuji Kusaka 2203 posts 4220 karma points
    Mar 01, 2011 @ 17:03
    Fuji Kusaka
    0

    Yours actually.....i needed to removed the for-each loop on my parent node to get the child node working and at same forgot to add a class in my css.

     

    <xsl:if test="$currentPage/ancestor-or-self::*[@isDoc]/@id = current()/@id">   
           
    <xsl:attribute name="class">current</xsl:attribute>
    </xsl:if>

     Thanks

    /fuji

     


     

  • Kim Andersen 1447 posts 2197 karma points MVP
    Mar 01, 2011 @ 17:19
    Kim Andersen
    0

    Okay cool to hear that. I couldn't understand what was wrong with the code I posted as I have used it myself earlier, so I got a bit confused there :)

    /Kim A

  • Morten Balle 38 posts 129 karma points
    Mar 11, 2011 @ 18:38
    Morten Balle
    0

    Hi guys

     

    Have taken the opportunity to follow this, and it works just fine. Thanks!

    However I would like to keep certain document types away from the dropdown.
    I've been struggeling with how to do that in Umb ver. 4.5.2....

    Can you help me out here..?

    Thanks

    Best,
    Morten

     

     

  • Fuji Kusaka 2203 posts 4220 karma points
    Mar 14, 2011 @ 08:34
    Fuji Kusaka
    0

    Hi Morten,

    What do you mean by document types?? If am not mistaken you dont need any document type for the drop down Navigation...all you need is an XSLT file.

    With the new release of umbraco v4.7 its more fun using Razor

     

    /Fuji

     

  • Morten Balle 38 posts 129 karma points
    Mar 14, 2011 @ 08:55
    Morten Balle
    0

    Hi Fuji

    In my nodetree I have pages created with document type "SiteStandard" ande some withe documenttype "ItemElement"

    It's only the nodes with "SiteStandard" I want to show in my dropdown.

    Nodes with "ItemElement" should be filtered away, as they are used for other purpose.

     

    Thanks

    Morten

  • Fuji Kusaka 2203 posts 4220 karma points
    Mar 14, 2011 @ 10:44
    Fuji Kusaka
    0

    What you can do is create another XSLT but choose "List Pages from Changeable Source' and create a source tab and just apply it to you template.

    Then you copy > paste the list style you used in the previous navigation.

     

    /Fuji

  • Morten Balle 38 posts 129 karma points
    Mar 14, 2011 @ 12:17
    Morten Balle
    0

    An acceptable workaround...,
    Thanks for pointing the direction, Fuji!

    Best,
    Morten

  • Carl 15 posts 36 karma points
    May 07, 2011 @ 17:09
    Carl
    0

    Hello everyone,

    This post has been very helpful. I am also pretty new in XSLT and had some issue incorporing it in my own nav.

    Here is the code

    <?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:uTube.XSLT="urn:uTube.XSLT" xmlns:ucomponents.dates="urn:ucomponents.dates" xmlns:ucomponents.search="urn:ucomponents.search" xmlns:PS.XSLTsearch="urn:PS.XSLTsearch"
      exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets uTube.XSLT ucomponents.dates ucomponents.search PS.XSLTsearch ">

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

    <xsl:param name="currentPage"/>

    <xsl:template match="/">
    <ul id="nav">
     
      <li>
    <xsl:if test="$currentPage/ancestor-or-self::*[@isDoc]/@id = current()/@id">
           <xsl:attribute name="class">current</xsl:attribute>
    </xsl:if>

          <a href="/">     
             <xsl:value-of select="$currentPage/ancestor-or-self::*/@nodeName"/>
          </a>  
     </li>
      
      <xsl:for-each select="$currentPage/ancestor-or-self::* [@level=$level]/* [@isDoc and string(umbracoNaviHide) != '1']">  
      <li>
         <xsl:attribute name="class">
             <xsl:if test="$currentPage/@id=@id">
              <xsl:text>current</xsl:text>
              </xsl:if>
         </xsl:attribute>
        
        
        <a href="{umbraco.library:NiceUrl(@id)}"><xsl:value-of select="@nodeName"/></a>    
      
      
        <!-- Drop Down Menu -->
        <xsl:if test="count(./* [@isDoc and string(umbracoNaviHide) != '1']) &gt; 0">
           <ul>
             <xsl:for-each select="./* [@isDoc and string(umbracoNaviHide) != '1']">
                 <li>
                   
    <xsl:if test="$currentPage/ancestor-or-self::node/@id = current()/@id">
           <xsl:attribute name="class">current</xsl:attribute>
    </xsl:if>

                   
                   <a href="{umbraco.library:NiceUrl(@id)}"><xsl:value-of select="@nodeName"/></a></li>
             </xsl:for-each>
           </ul>
        </xsl:if>
        <!-- End of Drop Down Menu -->
        
      </li>
      </xsl:for-each>
      
    </ul>

    </xsl:template>

    </xsl:stylesheet>

     

    And error I'm receiving from Umbraco XSTLT editor

    "System.Xml.Xsl.XslLoadException: The variable or parameter 'level' is either not defined or it is out of scope."

     

    One last question: What XSLT editor is perferred? I would like to work with XSLT but I'm not sure what editor to use.

     

    Thank you for everyones help and time

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    May 07, 2011 @ 18:02
    Jan Skovgaard
    0

    Hi Carl

    You get the error because you have not defined a variable named "level".

    In this part

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

    you make sure that nodes are only selected from the level that is specified in the $level variable...only problem is though that it does not exist :-)

    So in order to make it work you need to specify the variable of course.

    You can specify it right after the <xsl:template match="/"> or right before it.

    Do it like this

    <xsl:variable name="level" select="1" />

    You could also skip using this variable and instead write the level directly in the for-each section like this

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

    For editing XSLT files I'm using visual studio when working on Windows. If you're using a Mac I think Textmate is what you would want to use. Also for Windows there is an editor that works like Textmate...I think it's called E-TextEditor.

    The benefit from using the editor in Umbraco is that you get the error messages when something is wrong when you're trying to save. When you edit the files outside of Umbraco you don't get the error messages and can save code that contains errors. But there is inbuilt error checking, which will notify you about possible syntax errors.

    I hope this makes sense to you.

    /Jan

  • Carl 15 posts 36 karma points
    May 08, 2011 @ 01:37
    Carl
    0

    Hey Jan,

    Thank you so much for your help! That solved an issue I was having for a long time. Please let me know where I can send the case of beer.

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    May 08, 2011 @ 09:03
    Jan Skovgaard
    0

    Hi Carl

    You're very welcome - I'm glad to hear you got it solved.

    If you're planning til attend Codegarden we can grab a beer - otherwise I think wee need to keep track in here: http://foamee.com/ :D

    Have a great day :-)

    /Jan

  • Fuji Kusaka 2203 posts 4220 karma points
    May 23, 2011 @ 11:09
    Fuji Kusaka
    0

    have you created an XSLT by Level or clean one?

     

    //fuji

  • Fuji Kusaka 2203 posts 4220 karma points
    May 23, 2011 @ 11:14
    Fuji Kusaka
    0

    have you created an XSLT by Level or clean one?

     

    //fuji

  • Tim Salter 17 posts 47 karma points
    Dec 13, 2011 @ 05:52
    Tim Salter
    0

    I have implemented the 2nd level macro and now all of the links are being shown in the menu system, both top and 2nd level.  I assume there are settings that must be placed in the CSS file, but I am not sure as to what or where.

    Any help would be greatly appreciated.

    Thank you,
    Tim - Umbraco Rookie

  • Morten Balle 38 posts 129 karma points
    Dec 13, 2011 @ 06:20
    Morten Balle
    0

    You're on track.

    You'll have to take a look at the rendered code an see which ID's or Classes you have for ie. the UL and LI's in the source, and make css according to these.

    <ul class="firstlevel">
      <li><a href="#">Item1<a/></li>
      <li><a href="#">Item2<a/></li>
            <ul class="secondlevel">
                 <li><a href="#">Item1<a/></li>
                 <li><a href="#">Item2<a/></li>
            </ul>
      <li><a href="#">Item3<a/></li>
    </ul>

    and css:


    .firstlevel {background-color:grey}
    .firstlevel li {color:red;}
    .firstlevel li a {text-decoration:none}
    .firstlevel li a:hover {text-decoration:underline}
    .firstlevel ul.secondlevel li {color:blue;}

  • Tim Salter 17 posts 47 karma points
    Dec 15, 2011 @ 05:16
    Tim Salter
    0

    Still having issues.  Now when the page appears, both the top and 2nd level menus appear (no drop down) and when I click on a page, it goes to the correct page, but the menu disappears and an error message appears - Error parsing XSLT file: \xslt\umbTopNavigation.xslt. 

    Here is the code:

    <?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"/>

    <!-- Input the documenttype you want here -->
    <xsl:variable name="level" select="1"/>

    <xsl:template match="/">
         
    <ul id="top-navigation">

      <li>
        <xsl:attribute name="class">
          <xsl:if test="$currentPage/@level=$level">
            <xsl:text>current</xsl:text>
          </xsl:if>
        </xsl:attribute>

        <a href="/">    
          <xsl:value-of select="$currentPage/ancestor-or-self::*/@nodeName"/>
        </a>

      </li>

      <xsl:for-each select="$currentPage/ancestor-or-self::* [@level=$level]/* [@isDoc and string(umbracoNaviHide) != '1']"> 
        <li>
          <xsl:attribute name="class">
            <xsl:if test="$currentPage/ancestor-or-self::*[@isDoc]/@id = current()/@id">
              <xsl:attribute name="class">current</xsl:attribute>
            </xsl:if>
          </xsl:attribute>
         
          <a href="{umbraco.library:NiceUrl(@id)}"><xsl:value-of select="@nodeName"/></a>   
      
          <!-- Drop Down Menu -->
            <xsl:if test="count(./* [@isDoc and string(umbracoNaviHide) != '1']) &gt; 0">
              <ul>
                <xsl:for-each select="./* [@isDoc and string(umbracoNaviHide) != '1']">
                  <li>
                    <xsl:attribute name="class">
                      <xsl:if test="$currentPage/ancestor-or-self::*[@isDoc]/@id = current()/@id">
                        <xsl:attribute name="class">current</xsl:attribute>
                      </xsl:if>
                    </xsl:attribute>
                    <a href="{umbraco.library:NiceUrl(@id)}"><xsl:value-of select="@nodeName"/></a>
                  </li>
                  </xsl:for-each>
              </ul>
            </xsl:if>
          <!-- End of Drop Down Menu -->
        </li>
      </xsl:for-each>
     
    </ul> 
     
    </xsl:template>

    </xsl:stylesheet>

    Thanks for the help.

    Tim

Please Sign in or register to post replies

Write your reply to:

Draft