Copied to clipboard

Flag this post as spam?

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


  • Polity 5 posts 30 karma points
    Apr 07, 2010 @ 10:57
    Polity
    1

    ASP.Net GetXmlNodeByXPath with mutliple site roots

    Hi Guys,

    Using Umbraco 4.0.2.1, i ALWAYS have a menu included on my page, therefore i use the following source in a foreach in the xslt responsible for rendering the menu:

    umbraco.library:GetXmlNodeByXPath('.')/node[string(data [@alias='umbracoNaviHide']) != '1'

    This used to work fine untill we decided to implement multilanguage using multiple site roots. Basicly, GetXmlNodeByPath('.') does not give a damn about the current site root and just starts with the very most top level node which i assume to be the Top level (System?) 'Content' node.

    Actually, i'm not creating this site from scratch but editing an existing one and i had no influance in the initial development process, therefore i would like to make as few changes as possible.

    My question is: What would be a good way of rendering the main menu with respect to the current active site root?

    Altough i would be able to fall back to the area of my knowledge which is .NET and usercontrols on average and rewrite the submenu there, yet this would imply a major change and it excludes a learing change :)

    Cheers in advance for helping me out!

     

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Apr 07, 2010 @ 11:12
    Chriztian Steinmeier
    1

    Hi Polity,

    You do not need that library method for this - you should be able to get a reference to the current site root like this:

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

    - then use that in for-each/apply-templates to render nodes:

    <xsl:for-each select="$siteRoot/node[not(data[@alias = 'umbracoNaviHide'] = 1)]">
        ...
    </xsl:for-each>

    /Chriztian

  • Sebastiaan Janssen 5060 posts 15522 karma points MVP admin hq
    Apr 07, 2010 @ 12:43
    Sebastiaan Janssen
    0

    You don't even need the @level = 1 because the root node is called "root", so ancestor-or-self::node will stop at level 1 anyway.

    (which also means that you can still get to the root node outside of this site by doing ancestor-or-self::root).

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Apr 07, 2010 @ 12:52
    Chriztian Steinmeier
    3

    @Sebastiaan: Not entirely correct sir :-)

    Try this (when $currentPage is at, say, level 3 or 4):

    <xsl:value-of select="count($currentPage/ancestor-or-self::node)" />

    versus this:

    <xsl:value-of select="count($currentPage/ancestor-or-self::node[@level = 1])" />

    There's a difference, right?

    /Chriztian

  • Polity 5 posts 30 karma points
    Apr 07, 2010 @ 12:58
    Polity
    1

    Works like a charm (also without the level filter as pointed out by Sebastiaan).

    Thnx for the help

  • Polity 5 posts 30 karma points
    Apr 07, 2010 @ 13:02
    Polity
    1

    @Criztian,

    Your right, the behaviour should be different although this is not in my case because i have a extra filter (only selecting those wo are children of a certain top-level document type).

    I can recommend explicitly using the level filter due to the fact that it makes the code better understandable (you explicitly specify you only want the nodes from the top level.

     

  • Sebastiaan Janssen 5060 posts 15522 karma points MVP admin hq
    Apr 07, 2010 @ 15:20
    Sebastiaan Janssen
    0

    @Criztian Very cool, I never thought of that! Because of the filter you only get one node back, clever. I do suppose it performs a LITTLE worse because of the filter, but it shouldn't be noticable.

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Apr 07, 2010 @ 18:16
    Chriztian Steinmeier
    0

    @Sebastiaan: Would be cool to do some performance tests on that. My guess is the filter version is better performance wise, 'coz I think that's one of the areas where an XSLT processor goes out of its way to optimize stuff.

    /Chriztian

Please Sign in or register to post replies

Write your reply to:

Draft