Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Ayo Adesina 445 posts 1059 karma points
    Aug 27, 2011 @ 21:17
    Ayo Adesina
    0

    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.

  • Sebastian Dammark 583 posts 1407 karma points
    Aug 27, 2011 @ 21:51
    Sebastian Dammark
    0

    Try this:

    $currentPage/ancestor-or-self::root[@isDoc]/Website_EN/SliderImage_Folder/LinkBlock

  • Jesper Hauge 298 posts 487 karma points c-trib
    Aug 27, 2011 @ 23:19
    Jesper Hauge
    0

    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:

    $currentPage/ancestor::root/Website_EN/SliderImage_Folder/LinkBlock

    Regards
    Jesper Hauge 

  • Ayo Adesina 445 posts 1059 karma points
    Aug 28, 2011 @ 00:28
    Ayo Adesina
    0

    Thanks Guys.

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Aug 28, 2011 @ 16:45
    Jan Skovgaard
    0

    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

  • Rob Watkins 369 posts 701 karma points
    Aug 30, 2011 @ 18:14
    Rob Watkins
    0

    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?

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Aug 30, 2011 @ 19:05
    Chriztian Steinmeier
    0

    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):

    <xsl:variable name="siteRoot" select="$currentPage/ancestor-or-self::*[@level = 1]" />

    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:

    <xsl:apply-templates select="$siteRoot/Textpage[not(umbracoNaviHide = 1)]" />

    "Take all the visible pages below the site's root."

    /Chriztian

  • Rob Watkins 369 posts 701 karma points
    Aug 31, 2011 @ 11:18
    Rob Watkins
    0

    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!

Please Sign in or register to post replies

Write your reply to:

Draft