for a specific problem I had to mess about a bit making this work so I thought I'd share the working code
I have some embeedded content and if no selections are made then I need to take the selections from the parent page or parent page above that, in this case it's for a set of "rotating" banners and if no banners are chosen for the current page then use the banners set for the parent (unless this has no banners set, so then use those set on the parent of that etc.) all the way back to home which we can assume does have some set
the normal "empty" approach doesn't necessarily work as there may or may not be item/ so I am using a count of item and then getting the first result (as the ancestor-or-self will return all up to home but I want the one closest to self)
The trick to know with this is that there's a difference between using a positional predicate (e.g. [2]) *as part of the XPath using the axis*, and using it on a variable/parameter (these contains node sets, which are always in "document order").
Examples:
Home
News
First Item
Next Item
Let's pretend $currentPage is at "Next Item".
Set a variable to grab $currentPage and its ancestors:
but instead now I am using a Multi Node Tree Picker control rather than the embedded content
it has not quite worked
a document property is inherited by all page which is an MNTP data type for a "logo picker" I have a "Media" select tree type, it starts in a "client logos" media "folder" and has an xpath filter of /* this allows the user to pick some logos to show on the page with an article if the article has a parent (ie belongs to a section) and a logo selection is made for a parent but the current node does not have any items picked (ie count of items is zero) then it will use the logos selected for the parent
recursive embedded content
loving this embedded content control so much :)
for a specific problem I had to mess about a bit making this work so I thought I'd share the working code
I have some embeedded content and if no selections are made then I need to take the selections from the parent page or parent page above that, in this case it's for a set of "rotating" banners and if no banners are chosen for the current page then use the banners set for the parent (unless this has no banners set, so then use those set on the parent of that etc.) all the way back to home which we can assume does have some set
the normal "empty" approach doesn't necessarily work as there may or may not be item/ so I am using a count of item and then getting the first result (as the ancestor-or-self will return all up to home but I want the one closest to self)
so the code I got to is:
but if anyone else can see a better way then very interested too :)
so I had a problem with this
what I found was that I am not getting ancestor-or-self in reverse document order, not sure why
via Twitter I got some help from @greystate
@johncscott [1/2] - So you can reverse sort them using the level attribute if you have them in a variable... Makes sense?@johncscott ancestor-or-self::*[1] will take the closest, but if you put them in a variable and later do $var[1] you'll get the topmost12 hours ago
Aaah so @level ?
Can I put that in the XPATH or does it need to be in a separate xsl:sort?
Hi John,
The trick to know with this is that there's a difference between using a positional predicate (e.g. [2]) *as part of the XPath using the axis*, and using it on a variable/parameter (these contains node sets, which are always in "document order").
Examples:
Let's pretend $currentPage is at "Next Item".
Set a variable to grab $currentPage and its ancestors:
Now take the first in that set:
Which will give you "Home"
But if you do it all in the value-of it'll give you something else:
- here you get "Second Item"... (!)
So, to use them in the order you want, you can use the @level attribute that all Umbraco nodes have, and these will have their own unique value:
Hope that helps - otherwise, you know my number :-)
/Chriztian
- and no, you can't include the sorting in the XPath :-(
i've been looking at this again
but instead now I am using a Multi Node Tree Picker control rather than the embedded content
it has not quite worked
a document property is inherited by all page which is
an MNTP data type for a "logo picker" I have a "Media" select tree type, it starts in a "client logos" media "folder" and has an xpath filter of /*
this allows the user to pick some logos to show on the page with an article
if the article has a parent (ie belongs to a section) and a logo selection is made for a parent
but the current node does not have any items picked (ie count of items is zero)
then it will use the logos selected for the parent
this works nicely for the user
however the xslt is not quite working out
this is what I have:
But this is not reliable
Sometimes it does not show the logos collection from the right level.
Can you see the error of my ways?
is working on a reply...