Copied to clipboard

Flag this post as spam?

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


  • North Krimsly 59 posts 80 karma points
    Aug 02, 2010 @ 05:08
    North Krimsly
    0

    Output an image inside xsl:for-each, every iteration except the last one

    Greetings all,

    I'd like to output an image from my xslt script for every iteration of an xsl:for-each loop, except for the last iteration. Is there a way to "do something different" through some kind of an if-test, to see if we're in the last iteration of an xsl:for-each loop?

    Here's the pseudo-code:

    <xsl:for-each select="$currentPage/node [string(data [@alias='umbracoNaviHide']) != '1']">

    <!-- output an image here for every iteration of the loop, except for the last one! -->

    </xsl:for-each>

    Thanks in advance for your suggestions.

    -NorthK

     

  • Paul Blair 466 posts 731 karma points
    Aug 02, 2010 @ 05:55
    Paul Blair
    2
    <xsl:if test="position() != last()">
    ...do stuff
    </xsl:if>
  • Chriztian Steinmeier 2800 posts 8791 karma points MVP 8x admin c-trib
    Aug 02, 2010 @ 11:05
    Chriztian Steinmeier
    3

    Hi North,

    You can just exclude the last item from the processing by adding another predicate:

    <xsl:for-each select="$currentPage/node[not(data[@alias = 'umbracoNaviHide'] = 1)][not(position() = last())]">
       <!-- do stuff -->
    </xsl:for-each>

    (Also, in XSLT it's more common to use not(something = value) instead of something != value)

    /Chriztian 

  • North Krimsly 59 posts 80 karma points
    Aug 03, 2010 @ 05:47
    North Krimsly
    0

    Guys,

    Thanks a lot for taking the time to answer-- your suggestions worked perfectly!

    -NorthK

Please Sign in or register to post replies

Write your reply to:

Draft