Copied to clipboard

Flag this post as spam?

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


  • Another Fredrik 4 posts 24 karma points
    Feb 18, 2010 @ 10:32
    Another Fredrik
    0

    Menu, submenu problem

    I have a simple structure in my site tree.

    Home
        Subpage1
            SubSub1
            SubSub2
        Subpage2
        Subpage3

    My XSLT is based on the standard template but I added support to display the SubSub leves in an <ul>. This works kinda almost ;)

    If I browse to Home, Sub1,2,3 is displayed like it should. Browsing to Subpage1 displays SubSub1 and SubSub2 in a <ul> beneath Sub1. So far so good.

    Now, if I browse to Sub2 I get Sub3 (and every other SubX) in a <ul> like the SubSub's and I can't figure out why.

    Here is my XSLT.

    <xsl:output method="xml" omit-xml-declaration="yes" />
    
    <xsl:param name="currentPage"/>
    <xsl:variable name="level" select="1"/>
    
    <xsl:template match="/">
    
      <!-- The fun starts here -->
      <ul>
        <xsl:for-each select="$currentPage/ancestor-or-self::node [@level=$level]/node [string(data [@alias='umbracoNaviHide']) != '1']">
          <li>
            <a href="{umbraco.library:NiceUrl(@id)}">
              <xsl:if test="$currentPage/ancestor-or-self::node/@id = current()/@id">
                <xsl:attribute name="style">font-weight: bold;</xsl:attribute>
              </xsl:if>
              <xsl:value-of select="@nodeName"/>
            </a>
          </li>
          <xsl:if test="$currentPage/ancestor-or-self::node/@id = current()/@id">
            <ul>
              <xsl:for-each select="node">
                <li>
                  <a href="{umbraco.library:NiceUrl(@id)}">
                    <xsl:value-of select="@nodeName"/>
                  </a>
                </li>
              </xsl:for-each>
            </ul>
          </xsl:if>
        </xsl:for-each>
      </ul>
    
    </xsl:template>

    Help!

    /Another Fredrik

  • Another Fredrik 4 posts 24 karma points
    Feb 18, 2010 @ 11:26
    Another Fredrik
    0

    Ok, so I guessing im selecting something wrong in the 

    <xsl:for-each select="node">

    but I can't figure out what it really should be :(

    /Another Fredrik

  • Claushingebjerg 939 posts 2574 karma points
    Feb 18, 2010 @ 11:28
    Claushingebjerg
    0

    I would recommend uisng the "Cogwork Flexible Navigation" Package.

    It takes a lot of stress out of simple navigtaion, like the one your trying to build.

    http://our.umbraco.org/projects/cogworks---flexible-navigation

  • Another Fredrik 4 posts 24 karma points
    Feb 18, 2010 @ 11:36
    Another Fredrik
    0

    Ah, it looks great. I'll check it out. Still interested to find out what I did wrong so I can learn something :)

  • Kim Andersen 1447 posts 2196 karma points MVP
    Feb 18, 2010 @ 11:39
    Kim Andersen
    0

    Hi Frederik

    You could try this one out:

    <xsl:variable name="rootNode" select="$currentPage/ancestor-or-self::node [@level=2]" />
    <xsl:param name="currentPage"/>
      <xsl:template match="/">
        <ul id="subMenu">
              <!-- display normal umbraco navigation, take the tree from the active section -->
              <xsl:apply-templates select="$currentPage/ancestor-or-self::node [@level=2]/node [string(data [@alias='umbracoNaviHide']) != '1']"/>
            <li class="hide">
                <p>&nbsp;</p>
            </li>
        </ul>
      </xsl:template> 

    <xsl:template match="node[string(data [@alias='umbracoNaviHide']) != '1']" xml:space="default">
        <xsl:variable name="id" select="id" />
        <li class="subNiveau">
            <xsl:attribute name="class">subNiveau<xsl:if test="$currentPage/ancestor-or-self::node/@id = current()/@id"> current</xsl:if><xsl:if test="$currentPage/ancestor::node[@id = $id]"> ancestor</xsl:if>
          </xsl:attribute>
          <a href="{umbraco.library:NiceUrl(@id)}">
            <xsl:value-of select="@nodeName" disable-output-escaping="yes"/>
          </a>
        </li>
        <xsl:if test="count(./node) &gt; 0 and count(descendant-or-self::node [@id = $currentPage/@id]) &gt; 0 and ./node[@level &lt; 5]">
            <li class="subMenu2">
                <ul>       
                  <xsl:apply-templates select="./node" />       
                </ul>
            </li>   
        </xsl:if>
      </xsl:template>

    This works for me, and I use it everytime I need a submenu on one of my sites.

    /Kim A

  • Another Fredrik 4 posts 24 karma points
    Feb 18, 2010 @ 11:49
    Another Fredrik
    0

    Thanks Kim, looks quite similar to mine.

  • Kim Andersen 1447 posts 2196 karma points MVP
    Feb 18, 2010 @ 12:08
    Kim Andersen
    0

    Good to hear Frederik. It could be cool if you would report back, whether your problem was solved or not.

    /Kim A

Please Sign in or register to post replies

Write your reply to:

Draft