Copied to clipboard

Flag this post as spam?

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


  • Elad Lachmi 112 posts 144 karma points
    May 10, 2012 @ 16:15
    Elad Lachmi
    0

    Change variable value to count if it is 0

    Hi,

    I have the following code:

    <xsl:variable name="HowMany" select="/macro/HowMany" />
    <xsl:template match="/">

    <xsl:for-each select="$currentPage/child::*/broker [@isDoc][position() &lt;= $HowMany]">

    I want to set it up so that if HowMany is zero, the for-each will run for all positions.

    How can I do this?

    Thank you!

  • Chriztian Steinmeier 2798 posts 8788 karma points MVP 7x admin c-trib
    May 10, 2012 @ 23:36
    Chriztian Steinmeier
    1

    Hi Elad,

    You can use a little programmer trick:

    <xsl:for-each select="$currentPage/*/broker[@isDoc][position() &lt;= ($HowMany + 9999 * not($HowMany))]">

     

    If $HowMany is a positive number, not($HowMany) will return false(), which is converted to 0 (zero) for use in the multiplication. 0 times 9999 is 0, so we end up comparing position() to the number iin $HowMany.

    If, however, $HowMany is zero, not($HowMany) returns true(), which is converted to 1 - one times 9999 is 9999, which the current position() will likely be less than - so there you have it. 

    You just ned to make sure that 9999 is "big enough" in your context.

    /Chriztian 

  • Elad Lachmi 112 posts 144 karma points
    May 11, 2012 @ 10:08
    Elad Lachmi
    0

    Nice!

    Thank you!

Please Sign in or register to post replies

Write your reply to:

Draft