I've created a tree navigation, which worked perfectly for my needs until some bonehead user got the bright idea to create three tiers of navigation. : - ) Oh, the demands. Now my XSLT is inadequate. I've tinkered with it, but am still unable to sort out how to structure my templates. I'm close to a solution, but do not believe it is the most eloquent method and still is not as I want it. Ideally, it should iterate indefinitely by level, no? Even so, three or four levels should do the trick in this case.
Specs 1. The navigation should allow for indentation of each url by level. That works so far. See image below. 2. It should allow for style changes e.g. color, hover and background of the selected page and it's parent page(s) ONLY. The selected page in the image is test 02, yet my xslt allows all siblings on the same level to be selected, i.e. test 1 AND test 02
I've looked at it the thread you mention, but it appears uncertain they arrived at a valid solution. I tried to toy with it, but still no luck. Not at all certain what they are addressing there with "Site/Link". A very different approach than I want to go with. It seems hardwired to me and I like flexibility.
You are most certainly correct that the select statement needs tweaking, but wouldn't it be the latter, which tests level 2 URLs?
<xsl:variablename="subPages"select="./ *[@isDoc and string(umbracoNaviHide) != '1']"/> <xsl:iftest="$isCurrent and $subPages">
The post I mentioned was indeed not a perfect match, but I thought the test on the level like I proposed would work. Apparently not, damn ;-)
I may be wrong but I don't think the problem resides in the subPages. I think it comes from the fact that the ancestor-or-self statement, as it is writen, gets cousins of the last level as well.
Anyway, another option would be to add an extra check on the place where you test if you need to use the "current" class or not. Could you maybe try with this:
Michael, same results, different method ;-) I see where you are going. Odd that it differentiates level 1 and 2 elements from their respective cousins, but when it comes to level three it does not. Could this have any thing to do with the fact there is a style id for 1 and 2 but stops there? That was my initial thinking.
However, the styles seem to apply to level three in most cases, just not thye selected color attribute.
I don't think it has to do with the style-id's that stop at level2, because as far as I understand, it is the attribute "class=current" that gets wrongly set on the "cousin" nodes.
The result you get with your last example is indeed a good sign, it actually conforts me in thinking that the issue is only on the value of $isCurrent, but I must say I don't understand why my proposition with the extra check on levels did not do the trick :-s Because there we should actually exclude nodes on the same level as the currentpage, aka the cousins. Maybe for some reason the "@level" is not available? Maybe you could try to retrieve it explicitely then:
<xsl:iftest="$isCurrent and (@id = $currentPage/@id or umbraco.library:GetXmlNodeById(@id)/@level< $currentPage/@level)">
Michael, wish I could say that worked, but no dice. It sounds reasonable, what you said just before. It seems for some reason all is well on levels 1 and 2, but at level 3 all nodes on that level become current.
Maybe it is time for some debugging. Maybe at the end of your test on $isCurrent, after you have added the class attribute, you could output the @id, @level, $currentPage/@id and $currentPage/@level.
This might help us understand what is actually happening and why he keeps highlighting cousins.
Tree navigation styling
I've created a tree navigation, which worked perfectly for my needs until some bonehead user got the bright idea to create three tiers of navigation. : - ) Oh, the demands. Now my XSLT is inadequate. I've tinkered with it, but am still unable to sort out how to structure my templates. I'm close to a solution, but do not believe it is the most eloquent method and still is not as I want it. Ideally, it should iterate indefinitely by level, no? Even so, three or four levels should do the trick in this case.
Specs
1. The navigation should allow for indentation of each url by level. That works so far. See image below.
2. It should allow for style changes e.g. color, hover and background of the selected page and it's parent page(s) ONLY. The selected page in the image is test 02, yet my xslt allows all siblings on the same level to be selected, i.e. test 1 AND test 02
All suggestions welcome and appreciated.
Hi Dwayne,
I think the problem is that your test
Will retuen true for "cousins" also. See this post related to a similar problem: http://our.umbraco.org/forum/developers/xslt/18434-Syntax-question-ancestor-or-self-but-not-%27cousins%27
From what I read there, I think changing your test to someting like
I am not an XSLT expert so there might be a cleaner way, but I hope this helps you.
Cheers,
Michael.
Hey Michael,
I've looked at it the thread you mention, but it appears uncertain they arrived at a valid solution. I tried to toy with it, but still no luck. Not at all certain what they are addressing there with "Site/Link". A very different approach than I want to go with. It seems hardwired to me and I like flexibility.
You are most certainly correct that the select statement needs tweaking, but wouldn't it be the latter, which tests level 2 URLs?
Have tried. Same results as before.
By the way. I'm controlling styles with
The class .current sets the selected pages <a> styles.
Hi Dwayne,
The post I mentioned was indeed not a perfect match, but I thought the test on the level like I proposed would work. Apparently not, damn ;-)
I may be wrong but I don't think the problem resides in the subPages. I think it comes from the fact that the ancestor-or-self statement, as it is writen, gets cousins of the last level as well.
Anyway, another option would be to add an extra check on the place where you test if you need to use the "current" class or not. Could you maybe try with this:
I have put my code change in bold, hope it will remain visible with the formatting...
Hope this one wil work :-)
Cheers,
Michael.
Michael, same results, different method ;-) I see where you are going. Odd that it differentiates level 1 and 2 elements from their respective cousins, but when it comes to level three it does not. Could this have any thing to do with the fact there is a style id for 1 and 2 but stops there? That was my initial thinking.
However, the styles seem to apply to level three in most cases, just not thye selected color attribute.
We seem to be on the right track. Changed
to
and get
Hi Dwayne,
I don't think it has to do with the style-id's that stop at level2, because as far as I understand, it is the attribute "class=current" that gets wrongly set on the "cousin" nodes.
The result you get with your last example is indeed a good sign, it actually conforts me in thinking that the issue is only on the value of $isCurrent, but I must say I don't understand why my proposition with the extra check on levels did not do the trick :-s Because there we should actually exclude nodes on the same level as the currentpage, aka the cousins. Maybe for some reason the "@level" is not available? Maybe you could try to retrieve it explicitely then:
Let's hope ;-)
Cheers,
Michael.
Thanks. I'll try that. Meanwhile, I am looking here at a tree navi solution to see how it was constructed. maybe something here can help.
http://our.umbraco.org/forum/developers/xslt/9894-creating-an-expandable-tree-using-XSLT
Michael, wish I could say that worked, but no dice. It sounds reasonable, what you said just before. It seems for some reason all is well on levels 1 and 2, but at level 3 all nodes on that level become current.
Mmmhhh, very strange indeed :-(
Maybe it is time for some debugging. Maybe at the end of your test on $isCurrent, after you have added the class attribute, you could output the @id, @level, $currentPage/@id and $currentPage/@level.
This might help us understand what is actually happening and why he keeps highlighting cousins.
Cheers,
Michael.
Yeah, sounds reasonable.
is working on a reply...