Copied to clipboard

Flag this post as spam?

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


  • Dallas 133 posts 405 karma points
    Mar 28, 2011 @ 23:49
    Dallas
    0

    Test if the $currentPage is the descendant of a given page

    With xslt, how would I test if the $currentPage is the descendent of a given page?

    I need to set a selected class on a top level page when a descendant of that page is the $currentPage for a navigation menu.

    I am using 4.5.2 with the legacy style xslt.

    Thanks

    Dallas

  • Srdjan Lukic 34 posts 166 karma points
    Mar 28, 2011 @ 23:59
    Srdjan Lukic
    0

    Hi Dallas

    By using $currentPage/ancestor::*[@isDoc] you will be able to get all parents of the current page and that way make the selection

     

  • Sascha Wolter 615 posts 1101 karma points
    Mar 29, 2011 @ 01:59
    Sascha Wolter
    1

    Hey,

    using the old syntax this should work to find out if the current page in a loop (current()) is a parent of the $currentPage:

    <xsl:if test="current()/descendant-or-self::node[@id = $currentPage/@id]">

    </xsl:if>

    This will look if one of the descendants of the current node in the (omitted) xsl:for-each statement or the node itself has the same id as the id of the $currentPage. You can then set the class if the xsl:if is true.

    Hope that helps,

    Sascha

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Mar 29, 2011 @ 02:11
    Chriztian Steinmeier
    0

    @Sascha: You shouldn't need to start an XPath with current() - that's always the starting point. (Likewise with the oft-seen "./")

    /Chriztian

  • Sascha Wolter 615 posts 1101 karma points
    Mar 29, 2011 @ 02:33
    Sascha Wolter
    0

    Thanks Chriztian, I remember having run into some trouble and that adding current() fixed it, but it is most probably that the error was actually something else and I just got used to writing it explicitly each time (9 characters!). Anyway, glad that you posted your answer and cleared that up, I'll try to get rid of the habit. :)

    BTW: you've got one of my votes for MVP as I'm very grateful that you're sharing your Xsl wisdom with all of us! Greatly appreciated and I can say that I've learned a lot by reading your posts. :D

    Cheers,

    Sascha

  • Dallas 133 posts 405 karma points
    Apr 14, 2011 @ 10:22
    Dallas
    0

    Thanks for the responses.

    Srdjan, you put me on the right track by using the ancestor axes selector to get the parents. i was thinking about it backwards.  I was able to test for the top level item and set the class if it matched.

    is @isDoc part of the new schema as I was not able to get that to work, and it is not an attribute I can see in the umbraco xml cache?

  • Srdjan Lukic 34 posts 166 karma points
    Apr 14, 2011 @ 10:35
    Srdjan Lukic
    0

    Hi Dallas

    You are welcome. I'm not sure if @isDoc is only in new schema, I havent been using the old schema that much in umbraco. But it is just a bool return if the node is document. If you are using the new schema you be able to see it if you output your $currentPage  <xsl:value-of select="$currentPage" />  and yes it is an attribute. all attributes start with @ so that way you can easy see what it is. 

     

     

Please Sign in or register to post replies

Write your reply to:

Draft