Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
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]
I think that you can do something like this:
<xsl:choose> <xsl:when test="$currentPage/mobileURL !=''"> <xsl:value-of select="$currentPage/mobileURL" /> </xsl:when> <xsl:otherwise> <xsl:value-of select="$currentPage/ancestor-or-self::*[@isDoc]/mobileURL" /> </xsl:otherwise></xsl:choose>
Hope this helps,
Not quite working. On the page where I set mobileURL it works. On any child pages however, I get 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 been a while for me as well, but don't you just put recursive="true" when you put the macro in your template?
If I use parent, as in
<xsl:value-of select="$currentPage/parent::*[@isDoc]/mobileURL" />
I get a value. Just not getting anything from ancestor-or-self.
As Amir said you could try to make the macro recursive, by doing this:
<umbraco:macro alias="nameofmacro" pagevalue="[$mobileURL]" runat="server"/>
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,
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.
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
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:
<xsl:value-of select="$currentPage/ancestor-or-self::*[normalize-space(mobileURL)]/mobileURL" />
Hope that helps explain why you couldn't get it to work,
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...
Write your reply to:
Image will be uploaded when post is submitted