Copied to clipboard

Flag this post as spam?

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


  • Max Öhman 42 posts 71 karma points
    Dec 22, 2010 @ 10:32
    Max Öhman
    0

    Get position of the third-last node, 4.5

    Hi everybody!
    I'm trying to figure out a good way of getting the position of the third-last node. I'm using a for-each to create a navigation menu and I really want change attributes of the last, second-last and third-last node.

    I've made some efforts using preceding-sibling:: but I'm still a bit new to all this and can't manage to completing my code. 

    Thank you for taking a look at my problem and hopefully you can help me out!

    Cheers /Max

  • Chriztian Steinmeier 2726 posts 8320 karma points MVP 4x admin c-trib
    Dec 22, 2010 @ 10:45
    Chriztian Steinmeier
    2

    Hi Max,

    Here's one way to get it - depends a little on what you're trying to achieve, but this will work inside the for-each:

    <xsl:if test="position() = last() - 2">
        <!-- do stuff -->
    </xsl:if>

    /Chriztian

  • Chris Koiak 700 posts 2626 karma points
    Dec 22, 2010 @ 10:48
    Chris Koiak
    0

    Hi Max,

    You can use the XLST functions count() and position() to achieve this.

    <xsl:for-each select="$yourNodes">
    <xsl:if test="position() = (count($yourNodes)-1)">
    2nd last node
    </xsl:if>
    <xsl:for-each>
  • Max Öhman 42 posts 71 karma points
    Dec 22, 2010 @ 16:17
    Max Öhman
    0

    Thank you so much, both of you!

  • 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