Copied to clipboard

Flag this post as spam?

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


  • Profiterole 232 posts 264 karma points
    May 10, 2011 @ 19:42
    Profiterole
    0

    how to alternate background color

    Hi guys!

    I want to alternate background color in a for-each. So the first value-of will be blue, than green, than blue again... But I can't use position() because sometime some values are not displayed (it's a docType parameter). So, I would have two blue or green value in a row.

    Do you have alternative to position() ?

    Thank you.

  • Lennart Stoop 304 posts 842 karma points
    May 10, 2011 @ 19:48
    Lennart Stoop
    0

    Are you perhaps using an if statement inside the loop to filter out the items that ypu don't want to be displayed?

    If so, you could also filter these out in the for-each select (e.g. with a guard [@docType = 'thisOne']) so you are sure you are only looping through items that need to be displayed, and can still use position().

  • Profiterole 232 posts 264 karma points
    May 10, 2011 @ 20:05
    Profiterole
    0

    If it's help :

     <xsl:for-each select="$records">
    <!-- Look for Yes to publish and empty parentID -->
          <xsl:if test="./fields/autoriserlapublication//value = 'Yes' and string(./fields/parentid//value) = ''">
       <cite style="margin-left:3px;"><xsl:value-of select="./fields/commentaire//value"/></cite>
    <!-- Now, for each records that have a value in parentID -->
          <xsl:variable name="parentID" select="id"/>
          <xsl:for-each select="$records[string(./fields/parentid//value) = $parentID]">
            <xsl:if test="./fields/autoriserlapublication//value = 'Yes'">
            <cite> <xsl:value-of select="./fields/commentaire//value"/></cite>            
           </xsl:if>
           </xsl:for-each>
        </xsl:if>
     </xsl:for-each>

    So, I want to change background color for the first for-each. But sometimes position is odd (or even) for two or more "main" records in a row. I try to make answers to comment. So in the first loop it displays main comments and in the inner loop it displays answer to the main comment.

    So I don't think I can use you idea.

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    May 10, 2011 @ 20:19
    Dennis Aaen
    0

    Hi,

    I will try to help you as best as I can.

    But after reading your quistion, I thought about how you can solve it like this.

    The way I think it can be resolved is through the modulus.

    So in your for-each statement you make a choose construction.

    <xsl:choose>
    <
    xsl:when test="position() mod 2 = 1">
    background blue

    </xsl:when
    >

    <
    xsl:otherwise>
    background green
    </xsl:otherwise
    >

    </xsl:choose
    >

    I hope you find a solution.
    If this is the correct way to do it, I hope to bear with me :)

    /Dennis

  • Lennart Stoop 304 posts 842 karma points
    May 10, 2011 @ 20:20
    Lennart Stoop
    0

    I think you should still be able to use position() in your main loop if you drop the if statement, like so:

     <xsl:for-each select="$records[./fields/autoriserlapublication//value = 'Yes' and string(./fields/parentid//value) = '']">
         <cite style="margin-left:3px;"><xsl:value-of select="./fields/commentaire//value"/></cite>
         <xsl:variable name="parentID" select="id"/>
         <xsl:for-each select="$records[string(./fields/parentid//value) = $parentID]">
           <xsl:if test="./fields/autoriserlapublication//value = 'Yes'">
             <cite<xsl:value-of select="./fields/commentaire//value"/></cite>            
           </xsl:if>
         </xsl:for-each>
     </xsl:for-each>
  • Profiterole 232 posts 264 karma points
    May 10, 2011 @ 20:28
    Profiterole
    0

    Yeah you were right! I can use position() if I drop the if statement!

Please Sign in or register to post replies

Write your reply to:

Draft