As far as I know there's not a way of getting all of the siblings with XPath like you can get the parent, child, following-sibling etc. It would be nice though, to have an axis just called "sibling" or "siblings" that would get all of the siblings to the current node.
Since an XML node can only ever have one single parent node, I actually think that it's pretty efficient to go up to that one and then select all children (which itself is a fast XPath selection), instead of trying to combine preceding-sibling::, self:: and following-sibling:: in another axis...
One tiny optimization to the selection would be to skip the [@isDoc] predicate in the selection - currentPage is always a document; and a document can only be the child of another document, so...
In fact, you can just use the ../ shortcut to select the parent with:
Getting nodes on the same level including the nodes above $currentPage
Hi,
I am working on a solution where the sub menu should be shown if $currentPage has no subpages.
So if $currentPage has no childs the sub menu must consist of pages on the same level as you stand on.
I got it to list all following-sibling, but my problem is that I also need the siblings above $CurrentPage.
I'm using umbraco umbraco v 4.5.1.
My XSLT code looks like:
Hope someone can help me:)
/ Dennis Aaen
Hi Dennis
Could you try changing the for-each from this:
To this:
Then we'll go up to the parent node, and list all the childnodes from there. Haven't tested it though, but I think it will work.
/Kim A
Thanks Kim,
It worked just as it should:)
Great to hear Dennis.
As far as I know there's not a way of getting all of the siblings with XPath like you can get the parent, child, following-sibling etc. It would be nice though, to have an axis just called "sibling" or "siblings" that would get all of the siblings to the current node.
/Kim A
Yes I also looked after an XPath expression as sibling or siblings, which would then list all Siblings, but unfortunately there was not such an XPath expression:)
So glad that you could help me.
/Dennis Aaen
Just chippin' in with a couple of cents...
Since an XML node can only ever have one single parent node, I actually think that it's pretty efficient to go up to that one and then select all children (which itself is a fast XPath selection), instead of trying to combine preceding-sibling::, self:: and following-sibling:: in another axis...
One tiny optimization to the selection would be to skip the [@isDoc] predicate in the selection - currentPage is always a document; and a document can only be the child of another document, so...
In fact, you can just use the ../ shortcut to select the parent with:
Anyways - long reply to an already answered, closed & archived question - must be the Christmas Spirit in me :-)
...and if you really want that siblings axis - you could just create it yourself - here's a hint:
:-)
/Chriztian
Hi Chriztian,
Thanks for your suggestions.
It's always good to see several different ways to solve the same problems on. Especially for me who has worked with Umbraco professionally for about 4 months.
So I'm glad to see several ways to solve the same problem.:-)
/Dennis
is working on a reply...