It's been awhile since I wrote XSLT so I'm a bit rusty. I have a property in my Document Type that holds a string. I can get that string, no problem with
$currentPage/mobileURL
Now, if that property on the current page is empty, I want to go back up the tree until I find a value. I thought this worked in the past, but now it won't, gives me no value.
That's quite interesting, I have just tried setup a test site where I add a value on a child page, and on the parent page and on the pages that doesn't have a value on the mobileURL field, it takes it from the parent page, else it take it from the current
It's not the recursive thing on the macro you're after. It should be possible to use ancestor-or-self. But could you please share your full code? And perhaps a screemdump or something that illustrates your structure?
I was able to get it work using the method Dennis prescribed. That's how I did something similar several years ago, just did not recall the why or how. The ancestor-or-self should work, but it did not. The recursive works like a charm. Good enough until we get time to upgrade to Umbraco 7 next year.
Happy that you find a way to solve the case. And as you say then you can dig into it further when you have time or wait until you get time to upgrade to Umbraco 7.
I think you should mark the question as solved so if other comes across this post, then they can go directly to the solution that worked for you.
As you can see from Jan's link (thanks Jan :-), using the ancestor-or-self:: axis returns all of the nodes - but <xsl:value-of /> on a nodeset will only return the string value of the first node in that set, which in this case is $currentPage (the ancestor axes selects in reverse order).
The way to get an Umbraco recursive value with XSLT is to select all the nodes from the ancestor-or-self:: axis that have a value in the mobileURL property, and then take the first of those and output its mobileURL - like this:
Chriztian, that's similar to what I was thinking. I was thinking the self in ancestor-or-self is empty but is the first thing returned in the collection of values.
Value of page property, if empty then parent
It's been awhile since I wrote XSLT so I'm a bit rusty. I have a property in my Document Type that holds a string. I can get that string, no problem with
Now, if that property on the current page is empty, I want to go back up the tree until I find a value. I thought this worked in the past, but now it won't, gives me no value.
[Umbraco v 4.7.0]
Hi Connie,
I think that you can do something like this:
Hope this helps,
/Dennis
Not quite working. On the page where I set mobileURL it works. On any child pages however, I get no value.
Hi Connie,
That's quite interesting, I have just tried setup a test site where I add a value on a child page, and on the parent page and on the pages that doesn't have a value on the mobileURL field, it takes it from the parent page, else it take it from the current
/Dennis
It's been a while for me as well, but don't you just put recursive="true" when you put the macro in your template?
-Amir
If I use parent, as in
I get a value. Just not getting anything from ancestor-or-self.
Hi Connie,
As Amir said you could try to make the macro recursive, by doing this:
You can find the documentation here: https://our.umbraco.org/wiki/reference/templates/umbracomacro-element/macro-parameters/advanced-macro-parameter-syntax
Remember to change the alias of the macro so it match your case.
Hope this can help you,
/Dennis
Hi Connie
It's not the recursive thing on the macro you're after. It should be possible to use ancestor-or-self. But could you please share your full code? And perhaps a screemdump or something that illustrates your structure?
Don't know if it helps you but perhaps you can benefit from using the nice xpath axes visualizer by XSLT wizard Chriztian Steinmeier here http://pimpmyxslt.com/axesviz.aspx?contextNode=1073&axis=ancestor-or-self#screen
Looking forward to hearing more from you.
/Jan
I was able to get it work using the method Dennis prescribed. That's how I did something similar several years ago, just did not recall the why or how. The ancestor-or-self should work, but it did not. The recursive works like a charm. Good enough until we get time to upgrade to Umbraco 7 next year.
Hi Connie,
Happy that you find a way to solve the case. And as you say then you can dig into it further when you have time or wait until you get time to upgrade to Umbraco 7.
I think you should mark the question as solved so if other comes across this post, then they can go directly to the solution that worked for you.
/Dennis
Hi all,
Just to explain the
ancestor-or-self::
bit:As you can see from Jan's link (thanks Jan :-), using the ancestor-or-self:: axis returns all of the nodes - but
<xsl:value-of />
on a nodeset will only return the string value of the first node in that set, which in this case is$currentPage
(the ancestor axes selects in reverse order).The way to get an Umbraco recursive value with XSLT is to select all the nodes from the ancestor-or-self:: axis that have a value in the mobileURL property, and then take the first of those and output its mobileURL - like this:
Hope that helps explain why you couldn't get it to work,
/Chriztian
Chriztian, that's similar to what I was thinking. I was thinking the self in ancestor-or-self is empty but is the first thing returned in the collection of values.
is working on a reply...