Copied to clipboard

Flag this post as spam?

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


  • Anders Aleborg 35 posts 67 karma points
    Dec 29, 2010 @ 17:43
    Anders Aleborg
    0

    Problem with RunawayTopNavigation.xslt

    Hi,

    I'm using the RunawayTopNavigation.xslt with some modifications but it doesn't display the main node.
    My structure is like this:
    - Start (frontpage)
    - - Page 1
    - - Page 2
    - - Page 3

    Currently it only displays 

    Page 1  |  Page 2  |  Page 3

    But I want it to display the main node as well

    Start  |  Page 1  |  Page 2  |  Page 3

    From my xslt:

                <xsl:for-each select="$currentPage/ancestor-or-self::* [@level = $level]/* [string(umbracoNaviHide) != '1' and @isDoc]">
                  <xsl:choose>
          <!-- Check if the page is an external link -->
                    <xsl:when test="externalLink = 1">
                      <li id="mnu_{@nodeTypeAlias}">
                        <a href="{link}" title="{@nodeName}">
                          <xsl:value-of select="@nodeName"/>
                        </a>
                      </li>
                    </xsl:when>
                    <xsl:otherwise>
                      <xsl:choose>
              <!-- It's not external link so let's check if it's the active page and set a new class -->
                        <xsl:when test="$currentPage/ancestor-or-self::root//@id = @id">  
                          <li id="mnu_{@nodeTypeAlias}">
                            <a href="{umbraco.library:NiceUrl(@id)}" title="{@nodeName}" class="active">
                              <xsl:value-of select="@nodeName"/>
                            </a>
                          </li>
                        </xsl:when>
                        <xsl:otherwise>
                  <!-- Not an external link or the active page, display it normal -->
                          <li id="mnu_{@nodeTypeAlias}">
                            <a href="{umbraco.library:NiceUrl(@id)}" title="{@nodeName}">
                              <xsl:value-of select="@nodeName"/>
                            </a>
                          </li>
                        </xsl:otherwise>
                      </xsl:choose>
                    </xsl:otherwise>  
                  </xsl:choose>
                </xsl:for-each>
    
    Another problem is that all menu items, except external get the class="active"
    Any ideas?
  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Dec 29, 2010 @ 17:50
    Jan Skovgaard
    0

    Hi Anders

    Problem 1: It's because the XSLT will only give you those nodes under the root node, in this case your start page. I'm not sure how to make an elegant solution to it, but a pragmatic approach could be to simply just hardcode the link to the startpage outside of the for-each loop. I've done this on some occasions.

    Problem 2: Try altering this piece of code

    <xsl:when test="$currentPage/ancestor-or-self::root//@id = @id">

    to this instead

    <xsl:when test="$currentPage/ancestor-or-self::*/@id = current()/@id">

    Hope this helps

    /Jan

  • Kim Andersen 1447 posts 2196 karma points MVP
    Dec 29, 2010 @ 17:52
    Kim Andersen
    0

    Hi Anders

    To get the main node as well, you can insert this piece of code just before the for-each:

    <li>
    <a href="/">
    <xsl:if test="
    $currentPage/@level = '1'">
    <xsl:attribute name="class">active</xsl:attribute>
    </xsl:if>
    <xsl:value-of select="
    $currentPage/ancestor-or-self::* [@level = $level]/@nodeName" />
    </a>
    </li>

    /Kim A

  • Anders Aleborg 35 posts 67 karma points
    Dec 29, 2010 @ 18:29
    Anders Aleborg
    0

    Thanks Kim and Jan, that did the trick!

  • Anders Aleborg 35 posts 67 karma points
    Dec 29, 2010 @ 20:05
    Anders Aleborg
    0

    If I want to do the same thing in a submenu, so that the first node in the submenu is the parent node? How can I do that?

    <xsl:for-each select="$currentPage/ancestor-or-self::* [@level=$level]/* [@isDoc and string(umbracoNaviHide) != '1']">
    <xsl:choose>
    <xsl:when test="$currentPage/@id = @id">
      <li class="submenuactive">
        <a href="{umbraco.library:NiceUrl(@id)}">
          <xsl:value-of select="@nodeName"/>
        </a>
      </li>
    </xsl:when>
    <xsl:otherwise>
      <li>
        <a href="{umbraco.library:NiceUrl(@id)}">
          <xsl:value-of select="@nodeName"/>
        </a>
      </li>
    </xsl:otherwise>
    </xsl:choose>
    </xsl:for-each>
  • Kim Andersen 1447 posts 2196 karma points MVP
    Dec 29, 2010 @ 20:15
    Kim Andersen
    0

    You can probably change your code to this:

    <xsl:variable name="subNode" select="$currentPage/ancestor-or-self::* [@level=$level]" />
    <li>

       
    <a href="umbraco.library:NiceUrl($subNode/@id)">

         
    <xsl:value-of select="
    $subNode/@nodeName" />
       
    </a>
    </li>

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

    Then you'll also save some writing, because you don't have to use that xsl:choose, when the only difference is the class on the li-tag, when the node is active.

    /Kim A

  • Anders Aleborg 35 posts 67 karma points
    Dec 29, 2010 @ 22:32
    Anders Aleborg
    0

    thanks, but this: {umbraco.library:NiceUrl($subNode/@id)}
    Gives me: System.OverflowException: Value was either too large or too small for an Int32.

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Dec 29, 2010 @ 22:34
    Jan Skovgaard
    0

    Hi Anders

    That's because the XSLT does not know the value before runtime. So in this case you can safely check the "Skip error testing" checkbox when you save your XSLT.

    /Jan

Please Sign in or register to post replies

Write your reply to:

Draft