Hi guys I have got a list of images in my umbraco content...
but all the experience I have had with xslt in umbraco I have always accessed content via currentpage()/blablabla
but now I want to access content from the root I have tried:
root/Website_EN/SliderImage_Folder/LinkBlock
with no luck, can any one tell me how I can navigate from the root in umbraco, so that my macro will work on every template no matter where it sits in the site.
AFAIK the root node doesn't have an isDoc attribute, when running an Umbraco site with the "new" xml schema, so the xpath above will not work since it's looking for a "root" node with this attribute. Also you can be sure that the $currentPage is never equal to the root-node of the xml, so the xpath below should do what you want:
I just want to add that you in some situations can also benefit from the umbraco extension called GetXmlNodeById(), which returns the xml for the node an children nodes for the id that you feed it with.
I'm just mentioning it to make you aware of the option. The above samples will work just fine and is probaby more than fine to solve your current issue :-)
I have seen a lot of examples that select up from $currentPage to the root then down again to the required node - is there any difference / advantage of doing this way over using umbraco.library:GetXmlAll() and just selecting down?
You really shouldn't need to use GetXmlAll() - $currentPage gives you access to the complete tree - though there's a couple of things one needs to know about, when working in the context of an Umbraco macro.
I usually create a siteRoot variable after the currentPage parameter, which gives me access to the topnode in the current website (you can go all the way up to root if you prefer):
It's a simple selector that's executed blazingly fast on even very large trees - I don't really know how much is involved in performing the call to GetXmlAll() - but knowing it's completely unnecessary, I can't see the benefit of going "outside" to get back in, if you understand...
Having this variable, it's much easier to see what's going on in the rest of the stylesheet, e.g. building a top navigation:
I guess I have been using GetXmlAll as a hangover from when I first started Umbraccing, I thought $currentPage just held the subtree, not a location in the main tree. I'll change my patterns - as you say, it makes sense to not call another extension if you don't need to!
Get Content From Root Node xpath
Hi guys I have got a list of images in my umbraco content...
but all the experience I have had with xslt in umbraco I have always accessed content via currentpage()/blablabla
but now I want to access content from the root I have tried:
root/Website_EN/SliderImage_Folder/LinkBlock
with no luck, can any one tell me how I can navigate from the root in umbraco, so that my macro will work on every template no matter where it sits in the site.
Try this:
$currentPage/ancestor-or-self::root[@isDoc]/Website_EN/SliderImage_Folder/LinkBlock
AFAIK the root node doesn't have an isDoc attribute, when running an Umbraco site with the "new" xml schema, so the xpath above will not work since it's looking for a "root" node with this attribute. Also you can be sure that the $currentPage is never equal to the root-node of the xml, so the xpath below should do what you want:
Regards
Jesper Hauge
Thanks Guys.
Hi Ayo
I just want to add that you in some situations can also benefit from the umbraco extension called GetXmlNodeById(), which returns the xml for the node an children nodes for the id that you feed it with.
I'm just mentioning it to make you aware of the option. The above samples will work just fine and is probaby more than fine to solve your current issue :-)
/Jan
I have seen a lot of examples that select up from $currentPage to the root then down again to the required node - is there any difference / advantage of doing this way over using umbraco.library:GetXmlAll() and just selecting down?
Hi Rob,
You really shouldn't need to use GetXmlAll() - $currentPage gives you access to the complete tree - though there's a couple of things one needs to know about, when working in the context of an Umbraco macro.
I usually create a siteRoot variable after the currentPage parameter, which gives me access to the topnode in the current website (you can go all the way up to root if you prefer):
It's a simple selector that's executed blazingly fast on even very large trees - I don't really know how much is involved in performing the call to GetXmlAll() - but knowing it's completely unnecessary, I can't see the benefit of going "outside" to get back in, if you understand...
Having this variable, it's much easier to see what's going on in the rest of the stylesheet, e.g. building a top navigation:
"Take all the visible pages below the site's root."
/Chriztian
Makes sense to me!
I guess I have been using GetXmlAll as a hangover from when I first started Umbraccing, I thought $currentPage just held the subtree, not a location in the main tree. I'll change my patterns - as you say, it makes sense to not call another extension if you don't need to!
is working on a reply...