Copied to clipboard

Flag this post as spam?

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


  • Garry Bain 149 posts 124 karma points
    Sep 06, 2011 @ 14:51
    Garry Bain
    0

    Simple XSLT problem with xsl:for-each select="$currentPage"

    Hi everyone,

    I currently have a macro showing news items on the home page. This works fine when placed on the home page as the path is correctly pointing towards my articles:

    <xsl:for-each select="$currentPage/*/umbNewsArticle [@isDoc]">
    <xsl:value-of select="introduction" disable-output-escaping="yes"/>
    <p><a href="{umbraco.library:NiceUrl(@id)}">Read More</a></p>
    </xsl:for-each> 

    However, as soon as I go to a different page, the information disappears - as the $currentPage/*/umbNewsArrticle is now pointing to the wrong place.

    How can I adjust my code so that the select statement will always point to the same place. My site structure is as follows:

    Home

            - News Landing Page

                             - News Item 1

                             - News Item 2

                             - News Item 3

    Any help would be brilliant, cheers.
    Garry.

  • Bas Schouten 135 posts 233 karma points
    Sep 06, 2011 @ 14:58
  • Fuji Kusaka 2203 posts 4220 karma points
    Sep 06, 2011 @ 15:04
    Fuji Kusaka
    1

    Hi Gary you could change your XSLT code to something like

     <xsl:variable name="source" select="1200"/> 

    <xsl:template match="/">
    <
    xsl:for-each select="umbraco.library:GetXmlNodeById($source)/* [@isDoc and string(umbracoNaviHide) != '1']">
    <
    xsl:value-of select="introduction"disable-output-escaping="yes"/>
    <
    p><a href="{umbraco.library:NiceUrl(@id)}">Read Morea>p>

    </xsl:template>

     

    Hope this helps

     

    //fuji

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Sep 06, 2011 @ 15:08
    Dirk De Grave
    3

    Or use,


    <
    xsl:value-ofselect="introduction"disable-output-escaping="yes"/>
    <xsl:for-eachselect="$currentPage/ancestor-or-self::* [@level = 1]//* [name() = 'umbNewsArticle']">
    <p><ahref="{umbraco.library:NiceUrl(@id)}">Read Morea>p>
    xsl:for-each>

    which will travel up your tree until it finds a node at level 1 (=Home) and find all descendants (regardless of level) of type umbNewsArticle.

     

    Cheers,

    /Dirk

     

  • Garry Bain 149 posts 124 karma points
    Sep 06, 2011 @ 15:11
    Garry Bain
    0

    Thank you both very much.

    Fixed it with Fuji's code - thanks!

  • Anthony Candaele 1197 posts 2049 karma points
    Sep 06, 2011 @ 15:25
    Anthony Candaele
    0

    personally I more like Dirk's code because it is more generic (you don't need to hard code the id).

    greetings,

    Anthony

Please Sign in or register to post replies

Write your reply to:

Draft