Copied to clipboard

Flag this post as spam?

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


  • Jonas Eriksson 930 posts 1825 karma points
    Sep 10, 2009 @ 10:10
    Jonas Eriksson
    0

    Select topnavigation level depending on branch

    I wanted to use the same topnavigation macro to show different level nodes depending on which branch the user is on. More specifically : if the user is on a page under node @id 1070 he/she should see topnavigation from level 2, otherwise from level 1.

    I came up with the following xslt which works, but I wonder if it could be done in a better way?

    <xsl:variable name="level">
    <xsl:choose>
    <!-- if we are under member pages the top navigation should show level 2 -->
    <xsl:when test="count($currentPage/ancestor-or-self::node[@id = 1070])=1">
    2
    </xsl:when>
    <xsl:otherwise>
    1
    </xsl:otherwise>
    </xsl:choose>
    </xsl:variable>

  • Len Dierickx 150 posts 92 karma points
    Sep 10, 2009 @ 14:20
    Len Dierickx
    1

    Hi Jonas, 

    Looks fine for me, the only thing I would not do is put IDs of a page hardcoded inside XSLT.

    I think it would be better to add another variable, which can be set through a macro property.

    <xsl:variable name="memberNode" select"/macro/memberNode"/>
    ...
    <xsl:when text="count($currentPage/ancestor-or-self::node[@id = number($memberNode)])=1">

    But basically, I think your solution should work just fine.

  • Dirk De Grave 4537 posts 6006 karma points MVP 3x admin c-trib
    Sep 10, 2009 @ 15:17
    Dirk De Grave
    1

    I think it's even possible to remove the count() function and only have:

    <xsl:when test="$currentPage/ancestor-or-self::node[@id = 1070]">

    (altho have no stats to backup that this solution would be faster)

    Second Len's solution, you should not hard code the id

     

    Cheers,

    /Dirk

  • Jonas Eriksson 930 posts 1825 karma points
    Sep 11, 2009 @ 08:34
    Jonas Eriksson
    0

    Ok, thanks!

    Jonas

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies