Link to home
Start Free TrialLog in
Avatar of jsm11482
jsm11482

asked on

XSLT for-each conditional table rows

Bad title, I know.  I have a XML file part of which contains a bunch of "Nutrient" elements. I want to display these in a table, 2 nutrients per row. My current XSL is:

            <xsl:for-each select="Nutrient[@Type=2]">
                  <xsl:if test="position() mod 2 != 0">
                        <![CDATA[<tr>]]>
                  </xsl:if>
                  <td colspan="2" style="font-size: 10pt; font-family: Arial; background-color: #deebde; border-bottom: solid 1px #000000;">
                        <xsl:value-of select="@Name"/> <xsl:value-of select="@Amount"/>
                  </td>
                  <xsl:if test="position() mod 2 = 0 or position() = last()">
                        <![CDATA[</tr>]]>
                  </xsl:if>
            </xsl:for-each>

I put the <tr> and </tr> in CDATA because otherwise it would be angry that I didnt have a closing </tr>. This does not work of course and is also not correct, what is?

Thanks!
ASKER CERTIFIED SOLUTION
Avatar of Gertone (Geert Bormans)
Gertone (Geert Bormans)
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jsm11482
jsm11482

ASKER

Looks good, thanks!