Copied to clipboard

Flag this post as spam?

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


  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Dec 30, 2010 @ 17:05
    Dennis Aaen
    0

    Getting nodes on the same level including the nodes above $currentPage

    Hi,

    I am working on a solution where the sub menu should be shown if $currentPage has no subpages.

    So if $currentPage has no childs the sub menu must consist of pages on the same level as you stand on.

    I got it to list all following-sibling, but my problem is that I also need the siblings above $CurrentPage.

    I'm using umbraco umbraco v 4.5.1.

    My XSLT code looks like:

    <xsl:variable name="count" select="count($currentPage/child::* [@isDoc and string(umbracoNaviHide) != '1'])"/>

    <!-- The fun starts here -->

    <div id="submenu">
    <xsl:choose>
    <xsl:when test="$count != 0">
    <ul>
    <xsl:for-each select="$currentPage/child::* [@isDoc and string(umbracoNaviHide) != '1']">
      <li>
        <a href="{umbraco.library:NiceUrl(@id)}">
          <xsl:value-of select="pcd_master_menuTitle"/>
        </a>
      </li>
    </xsl:for-each>
    </ul>
    </xsl:when>
    <xsl:otherwise>
      <ul>
    <xsl:for-each select="$currentPage/following-sibling::* [@isDoc and string(umbracoNaviHide) != '1']">
      <li>
        <a href="{umbraco.library:NiceUrl(@id)}">
          <xsl:value-of select="pcd_master_menuTitle"/>
        </a>
      </li>
    </xsl:for-each>
    </ul>
    </xsl:otherwise>
    </xsl:choose>

     </div>

    Hope someone can help me:)

    / Dennis Aaen

  • Kim Andersen 1447 posts 2197 karma points MVP
    Dec 30, 2010 @ 19:23
    Kim Andersen
    2

    Hi Dennis

    Could you try changing the for-each from this:

    <xsl:for-each select="$currentPage/following-sibling::* [@isDoc and string(umbracoNaviHide) != '1']">

    To this:

    <xsl:for-each select="$currentPage/parent::*[@isDoc]/* [@isDoc and string(umbracoNaviHide) != '1']">

    Then we'll go up to the parent node, and list all the childnodes from there. Haven't tested it though, but I think it will work.

    /Kim A

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Dec 30, 2010 @ 19:27
    Dennis Aaen
    0

    Thanks Kim,

    It worked just as it should:)

  • Kim Andersen 1447 posts 2197 karma points MVP
    Dec 30, 2010 @ 19:33
    Kim Andersen
    0

    Great to hear Dennis.

    As far as I know there's not a way of getting all of the siblings with XPath like you can get the parent, child, following-sibling etc. It would be nice though, to have an axis just called "sibling" or "siblings" that would get all of the siblings to the current node.

    /Kim A

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Dec 30, 2010 @ 19:42
    Dennis Aaen
    0

    Yes I also looked after an XPath expression as sibling or siblings, which would then list all Siblings, but unfortunately there was not such an XPath expression:)

    So glad that you could help me.

    /Dennis Aaen

  • Chriztian Steinmeier 2800 posts 8791 karma points MVP 8x admin c-trib
    Dec 30, 2010 @ 23:22
    Chriztian Steinmeier
    0

    Just chippin' in with a couple of cents...

    Since an XML node can only ever have one single parent node, I actually think that it's pretty efficient to go up to that one and then select all children (which itself is a fast XPath selection), instead of trying to combine preceding-sibling::, self:: and following-sibling:: in another axis...

    One tiny optimization to the selection would be to skip the [@isDoc] predicate in the selection - currentPage is always a document; and a document can only be the child of another document, so...

    In fact, you can just use the ../ shortcut to select the parent with:

    <xsl:for-each select="$currentPage/../*[@isDoc][not(umbracoNaviHide = 1)]">

    Anyways - long reply to an already answered, closed & archived question - must be the Christmas Spirit in me :-)

    ...and if you really want that siblings axis - you could just create it yourself - here's a hint:

    <!ENTITY siblings "$currentPage/../*">

    :-)

    /Chriztian

     

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Dec 30, 2010 @ 23:45
    Dennis Aaen
    0

    Hi Chriztian,

    Thanks for your suggestions.

    It's always good to see several different ways to solve the same problems on. Especially for me who has worked with Umbraco professionally for about 4 months.

    So I'm glad to see several ways to solve the same problem.:-)

    /Dennis 

  • 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