Copied to clipboard

Flag this post as spam?

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


  • Matt Bertulli 7 posts 27 karma points
    Jan 22, 2010 @ 17:11
    Matt Bertulli
    0

    ancestor or self - is this not proper?

    We're trying to have a top-level menu navigation package work as follows.  The top menu will show only Level = 2 nodes, which it is doing properly.

    On each page however, we have multiple levels of nested content.  So for example, we have a site structure that looks like this:

    Our People (shown in top nav)
    - Lawyer 1 (shown on page left menu only)
    - Lawyer 2 ^

    When we're displaying the "Our People" in the top nav, we want to show that menu item as selected.  We currently have the following XSLT for displaying the top navigation and we're using ancestor-or-self to check if the $currentPage is a child of the current() top nav item.  This is the part that is not working.  We cannot get the current class to display on "Our People" when on the Lawyer 1, 2 pages.

    <xsl:for-each select="$currentPage/ancestor-or-self::node/node [@level = 2 and string(data[@alias='umbracoNaviHide']) != '1']">
                <li>
                    <!--
                    Add the class selected if the currentpage or parent nodes (up the tree to the root)
                    ID matches our current node ID in the for each loop
                    -->
                    <xsl:if test="$currentPage/ancestor-or-self::node/@id = current()/@id">
                        <xsl:attribute name="class">
                            <xsl:text>current</xsl:text>
                        </xsl:attribute>
                    </xsl:if>
                   
                    <a href="{umbraco.library:NiceUrl(@id)}">
                        <xsl:value-of select="current()/@nodeName" />
                    </a>
                </li>
            </xsl:for-each> 

  • Anders Burla 2560 posts 8256 karma points
    Jan 22, 2010 @ 20:13
    Anders Burla
    0

    This is the xslt im using in our menu xslt,

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

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

              <xsl:if test="$currentPage/ancestor-or-self::node/@id=@id and $currentPage/@id=@id">
                <xsl:attribute name="class">inpath selected</xsl:attribute>
              </xsl:if>

  • Matt Bertulli 7 posts 27 karma points
    Jan 22, 2010 @ 21:32
    Matt Bertulli
    0

    I had tried that, but it also does not work.  It works for showing the $currentPage as selected, but not the parent of the $currentPage in my top navigation.

  • Paul Blair 466 posts 731 karma points
    Jan 22, 2010 @ 22:54
    Paul Blair
    0

    Hi Matt,

    What you have there looks like it should work. Looks like you'll have to do some debugging to see where the problem lies.

    Try putting some output into your XSLT to see if the values are aas expected or if something funky is going on e.g.

    <xsl:value-of select="current()/@id" /> 

Please Sign in or register to post replies

Write your reply to:

Draft