Copied to clipboard

Flag this post as spam?

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


  • rs82uk 4 posts 24 karma points
    Oct 04, 2011 @ 23:20
    rs82uk
    0

    Getting the website root in xslt

    Im using the umbBusiness Site which has umbBusinessFrontpageNews.xslt

    I want to thave the news list appear in the sidebar of every page but the xslt page uses the following code

     

    <xsl:for-each select="$currentPage/umbNewsArea/umbNewsArticle [@isDoc and string(umbracoNaviHide) != '1']">

    So that I only get a list of the news articles on the homepage what can I replace

    $currentPage with to navigate to the homepage of the site? 

  • Rodion Novoselov 694 posts 859 karma points
    Oct 04, 2011 @ 23:32
    Rodion Novoselov
    0

    Use umbraco.library:GetXmlAll() instead of $currentPage like this:

    <xsl:for-each select="umbraco.library:GetXmlAll()//umbNewsArea/umbNewsArticle [@isDoc and string(umbracoNaviHide) != '1']">

    Note also the usage of '//' instead of '/' before 'umbNewsArea' in the snippet above - it will make XPath select all 'umbNewsArea' nodes notwithstanding the level.

  • rs82uk 4 posts 24 karma points
    Oct 04, 2011 @ 23:37
    rs82uk
    0

    Thanks alot sending you a virtual beer

  • Chriztian Steinmeier 2800 posts 8791 karma points MVP 8x admin c-trib
    Oct 05, 2011 @ 00:39
    Chriztian Steinmeier
    0

    Hi rs82uk (and Rodion),

    I'd recommend a simple XPath based off $currentPage for this - the GetXmlAll() extension really doesn't make much sense inside of XSLT - calling an extension function to fetch *everything* once more always seemed overkill to me - $currentPage *has* everything already (but I aknowledge that from a C# developer's viewpoint, it may be more transparent what it does...)

    Anyway, this is how I usually do this:

    <xsl:param name="currentPage" />
    <xsl:variable name="siteRoot" select="$currentPage/ancestor-or-self::*[@level = 1]" />
    
    <xsl:for-each select="$siteRoot//umbNewsArea/umbNewsArticle[@isDoc][not(umbracoNaviHide = 1)]">
        <!-- do stuff -->
    </xsl:for-each>

    Be careful with the double slash, though - if you know where the nodes are, it's much better to address them specifically, e.g.:

    $siteRoot/Textpage/umbNewsArea/etc.

    - this way, the processor will only search the specified path and not try all levels below to find the umbNewsArea nodes. 

    /Chriztian

     

Please Sign in or register to post replies

Write your reply to:

Draft