Copied to clipboard

Flag this post as spam?

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


  • kukuwka 75 posts 96 karma points
    Oct 06, 2010 @ 14:06
    kukuwka
    0

    Get count of items in for-each

    Hi,

    I want to know how many items fit to my 'when ':

    <xsl:variable name="count" select="1> 

     

    <

     

     

    xsl:for-each select="$items">

    <xsl:choose>

    <

     

     

    xsl:when test="somthing">

       <xsl:variable name="count">

              <

     

     

    xsl:value-of select="$count+1"/>

       </

     

     

    xsl:variable>

    </xsl:when>

     

     

     

     

    </xsl:choose>

     

     

     </xsl:for-each>

     but when I do:

     

    <

     

     

    xsl:value-of select="$count"/> I get alwayse 1.

    How can I get right number of items?

    Thanks,

    kukuwka

     

  • Magnus Eriksson 122 posts 362 karma points
    Oct 06, 2010 @ 14:22
    Magnus Eriksson
    0

    You can't change the values of variables in xslt. You might be able to use the count() function on a suitable node-set, where you have your "somthing" in the XPath expression.

    Regards,
    Magnus

  • Rik Helsen 670 posts 873 karma points
    Oct 06, 2010 @ 17:00
    Rik Helsen
    0

    use the position() function to know what iteration you are in ;)

     

    I just explained it here: http://our.umbraco.org/forum/developers/xslt/13316-How-to-get-number-of-items-in-for-each

    ps. don't double post ;)

Please Sign in or register to post replies

Write your reply to:

Draft