I'm trying to output the next two levels of navigation from a particular node. I can get the XSLT to output a list of the correct items, but I can't seem to get it to nest the list. i.e. I want it to output:
Your initial for-each select is calling all the descendant nodes, where it should be using just the first level, and then within the for-each, you can check if it has any child nodes - and loop accordingly.
You'll probably find it useful to use a recursive template for this. For a good example create a new xslt file and choose "sitemap" from the list of predefined templates.
In particular look at the drawNodes template, which operates as follows
This template draws out the child nodes of the parent node (which is passed in as paramater 'parent')
For each node encountered, the template checks to see if it has any child nodes
If it does, it calls itself but using the current node as the parent
rinse and repeat, up until it reaches a level that matches the stated max level
Hope this helps - best bet is to dissect the existing xslt for this, it's the best way to learn!
Dan, I did want to use recursive templates for this as it seems like the next gap up in my XLST understanding and I can see how it would make the solution above a bit neater. I tried to modify the 'list whole structure from current page' template initially, but couldn't get it to work quite right. I'll look into this though as it would help understand a lot of the XSLT structures in the packages I use (e.g. XSLT search etc). Back to W3Schools as soon as I get chance :)
Following on from Dan (Drayne)'s suggestion, here's a quick example of how to use recursive templates. Using apply-templates over for-each is nicer to the XSLT processor, (or so I am lead to believe).
If you follow down the logic of first template (match="/") ... it reaches the apply-templates, then goes to the template (match="node" ... because the XML element is called "node" and it matches it; obvious, I know!) Then inside the IF condition, the template is applied again.
Any questions, let us know!
Cheers, Lee.
PS. Where about in Bristol are you? You should come along to the next Umbraco Bristol (South West) meet-up? (twitter / contact me)
I'm based near Bristol harbour - in a studio very close to the SS Great Britain. I'd definitely be up for attending the next south-west meet-up. I know you guys have met up a couple of times recently, but I've just become a dad for the second time so things are a bit hectic at the moment and I'm not getting much time for 'extra-curricular' stuff :)
I'm trying to get a couple of other Bristol studios to start working with Umbraco, so I'll link them in too if they do. It would be good to build the SW community a little and have some more local companies on board.
Hi Dan, I know how it is... got a 2yo girl here! Fun & joys of fatherhood!
We're planning on making the Bristol meet-up bi-monthly (or whatever the word is for once every two months?), so next will be around mid-May. (No exact dates planned, so feel free to suggest a date that suits you?)
Nested list
Hi,
I'm trying to output the next two levels of navigation from a particular node. I can get the XSLT to output a list of the correct items, but I can't seem to get it to nest the list. i.e. I want it to output:
But it just outputs:
The code I'm using is this:
Can anyone see how I can do this?
Thanks all...
Hi Dan,
Your initial for-each select is calling all the descendant nodes, where it should be using just the first level, and then within the for-each, you can check if it has any child nodes - and loop accordingly.
I've removed the "maxLevelForNav" variable ... I didn't see a need for it. :-)
Cheers, Lee.
oops, missed a bit. Between the nested IF and FOR-EACH, put the <ul> tags.
You'll probably find it useful to use a recursive template for this. For a good example create a new xslt file and choose "sitemap" from the list of predefined templates.
In particular look at the drawNodes template, which operates as follows
Hope this helps - best bet is to dissect the existing xslt for this, it's the best way to learn!
Dan
Thanks Lee - that worked perfectly.
Dan, I did want to use recursive templates for this as it seems like the next gap up in my XLST understanding and I can see how it would make the solution above a bit neater. I tried to modify the 'list whole structure from current page' template initially, but couldn't get it to work quite right. I'll look into this though as it would help understand a lot of the XSLT structures in the packages I use (e.g. XSLT search etc). Back to W3Schools as soon as I get chance :)
Hi Dan,
Following on from Dan (Drayne)'s suggestion, here's a quick example of how to use recursive templates. Using apply-templates over for-each is nicer to the XSLT processor, (or so I am lead to believe).
If you follow down the logic of first template (match="/") ... it reaches the apply-templates, then goes to the template (match="node" ... because the XML element is called "node" and it matches it; obvious, I know!) Then inside the IF condition, the template is applied again.
Any questions, let us know!
Cheers, Lee.
PS. Where about in Bristol are you? You should come along to the next Umbraco Bristol (South West) meet-up? (twitter / contact me)
Cheers Lee, that's really really helpful.
I'm based near Bristol harbour - in a studio very close to the SS Great Britain. I'd definitely be up for attending the next south-west meet-up. I know you guys have met up a couple of times recently, but I've just become a dad for the second time so things are a bit hectic at the moment and I'm not getting much time for 'extra-curricular' stuff :)
I'm trying to get a couple of other Bristol studios to start working with Umbraco, so I'll link them in too if they do. It would be good to build the SW community a little and have some more local companies on board.
Hi Dan, I know how it is... got a 2yo girl here! Fun & joys of fatherhood!
We're planning on making the Bristol meet-up bi-monthly (or whatever the word is for once every two months?), so next will be around mid-May. (No exact dates planned, so feel free to suggest a date that suits you?)
is working on a reply...