Copied to clipboard

Flag this post as spam?

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


  • Dan 1250 posts 3747 karma points admin c-trib
    Aug 11, 2010 @ 15:17
    Dan
    0

    Get id of ancester-or-self from current node at specific level

    Hi,

    Standard requirement - I have sub-nav which I want to display on a parent page, and also on the child page, so I need to get the id of the ancester-or-self node from the current page at a parciular level then use this as the base for building the main subnav template.  I can't seem to get the syntax right with the new schema, in grabbing the ancestral id.  I have this:

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

    </xsl:template>

    I'm not sure how to modify the source select to target just @id for that node.  Can someone shed any light on this?

    Thanks!

  • Sebastiaan Janssen 4899 posts 14655 karma points MVP admin hq
    Aug 11, 2010 @ 15:30
    Sebastiaan Janssen
    0

    This should work:

    <xsl:param name="currentPage"/>
    
    <xsl:template match="/">
    <ul>
    <xsl:for-each select="$currentPage/../* [@isDoc and string(umbracoNaviHide) != '1']">
      <li>
        <a href="{umbraco.library:NiceUrl(@id)}">
          <xsl:value-of select="@nodeName"/>
        </a>
      </li>
    </xsl:for-each>
    </ul>
    
    </xsl:template>

    So instead of going all the way up the tree (using ancestor-or-self), you only go ONE step up to the parent (by using /..) and then show all the docs under the that page.

  • Dan 1250 posts 3747 karma points admin c-trib
    Aug 11, 2010 @ 15:40
    Dan
    100

    Thanks Sebastian - that's not going to work for showing the same nav on two levels though, as it's always going to go up the structure once.  It actually dawned on my whilst writing this that all I need is the standard 'get sub pages from level' script:

    <xsl:param name="currentPage"/>
    <xsl:variable name="level" select="2"/>
        
    <xsl:template match="/">
    <ul>
    <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>
      </li>
    </xsl:for-each>
    </ul>

    Doh!

    Thanks anyhow.

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies