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.
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
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?
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.
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
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
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
@Sascha: You shouldn't need to start an XPath with current() - that's always the starting point. (Likewise with the oft-seen "./")
/Chriztian
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
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?
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.
is working on a reply...