Copied to clipboard

Flag this post as spam?

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


  • suzyb 474 posts 932 karma points
    Jun 23, 2011 @ 10:16
    suzyb
    0

    "parent or self" select page or closest parent

    I have a list of sectors and sub sectors, both of which have their own content as child nodes. And I'd like to have sector specific navigation to show links to the list of content when you are viewing the sector page or one of those content pages.

    At the moment I'm using ancestor-or-self to display the sub navigation for the sectors.  However this selects all the sectors above me not just my parent sector.

    This is how I currently select the nav

    <xsl:variable name="records" select="$currentPage/ancestor-or-self::Sector/* [@isDoc and string(umbracoNaviHide) != '1']" />

    and my structure

    sector
    -- content page
    -- sector a
    ---- content page a

    How can I select only sector a when I'm in content page a or sector a page itself.

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Jun 23, 2011 @ 10:29
    Dirk De Grave
    0

    Can't you just use 

    <xsl:variablename="record"select="$currentPage/ancestor-or-self::Sector/* [@isDoc and string(umbracoNaviHide) != '1'][0]"/>

    which would only return the first from the list?

     

    Cheers,

    /Dirk

  • suzyb 474 posts 932 karma points
    Jun 23, 2011 @ 10:36
    suzyb
    0

    I think I may have caused confusion with my question again.

    As I understand your code it will only give me the first child node under a sector.  I want the first and closest parent sector to the child or the sector itself if in that page.

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Jun 23, 2011 @ 10:41
    Dirk De Grave
    0

    How about

    <xsl:variablename="record"select="$currentPage/ancestor-or-self::* [name() = 'Sector' and @isDoc and string(umbracoNaviHide) != '1'][0]"/>

    which would traverse up the tree for 'Sector' documents and return the first one?

     

    Cheers,

    /Dirk

     

  • Richard 146 posts 168 karma points
    Jun 23, 2011 @ 10:51
    Richard
    0

    To  list pages within a section of a web site, I used the following to find if I was either a "sector a" page or "content page a" page

    <xsl:variable name="sectionId">
    <xsl:choose>
    <xsl:when test="$currentPage/@level = 2">
    <xsl:value-of select="$currentPage/@parentID"/>
    </xsl:when>
    <xsl:otherwise>
    <xsl:value-of select="$currentPage/@id"/>
    </xsl:otherwise>
    </xsl:choose>

    and then use this sectionId to control which pages you list.

  • suzyb 474 posts 932 karma points
    Jun 23, 2011 @ 18:08
    suzyb
    0

    Richard's code helped me reach a solution

    <xsl:variable name="sectorLevel">
      <xsl:choose>
          <xsl:when test="$currentPage [name() = 'Sector']">
            <xsl:value-of select="$currentPage/@level"/>
          </xsl:when>
          <xsl:otherwise>
            <xsl:value-of select="$currentPage/@level - 1"/>
          </xsl:otherwise>
      </xsl:choose>
      </xsl:variable>

      <xsl:variable name="sector" select="$currentPage/ancestor-or-self::Sector[@level = $sectorLevel]" />

    Then I just use $sector in place of $currentPage/ancestor-or-self::Sector

    Thanks for the suggestions.

Please Sign in or register to post replies

Write your reply to:

Draft