Copied to clipboard

Flag this post as spam?

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


  • Stefan 117 posts 215 karma points
    Dec 05, 2011 @ 17:49
    Stefan
    0

    Parent-or-self?

    Hi.

    I have a sub-navigation menu in a sidebar which shows all children of the parent doctype.

    It is selected through this variable:

        <xsl:variable name="Items" select="umbraco.library:GetXmlNodeById($currentPage/parent::*[@isDoc]/@id)/textpage" />

    I wonder if there is an easy way to chose "parent or self", to make this work whether the currentpage is the folder containing textpages or the currentpage is one of the textpages? As now it only works if you are on a textpage.

    The level could also be tested and returned to the variable, but I cant seem to get the selector right.

        <xsl:choose>
          <xsl:when test="$currentPage/@level = 2">
            <xsl:value-of select = id of currentpage/textpage />
          </xsl:when>
          <xsl:otherwise>
            <xsl:value-of select = select the parent folder/textpage />
          </xsl:otherwise>
        </xsl:choose>

    Thanks for your help :-)

  • Chriztian Steinmeier 2726 posts 8320 karma points MVP 4x admin c-trib
    Dec 05, 2011 @ 22:37
    Chriztian Steinmeier
    0

    Hi Stefan,

    You're actually very close :-)

    It's called ancestor-or-self:: and will select all "parents" of currentPage as well as currentPage itself, but you can just include the level predicate to always select the node in the tree that's on level 2, whether it's currentPage or its parent:

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

    /Chriztian

  • Stefan 117 posts 215 karma points
    Dec 07, 2011 @ 00:38
    Stefan
    0

    Thank you for your help!

    I have just finished my examns in C - think my next project will be learning XSLT more in-depth. I have a feeling that the time will be well-spent ;)
    I did in fact play around with the ancestor-or-self axis, but I dont think I've got the syntax just right :/

  • 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