[xsl] creating a table with xslt

Subject: [xsl] creating a table with xslt
From: "Kimberly Begley" <kimberly.lewis@xxxxxxxxx>
Date: Mon, 17 Mar 2008 14:02:49 +1000
Hi,
This is my first post on  your forum - I was searching around for how
to implement a counter in xslt and this brought me to your user group.
I'm looking to do make a very simple table from an xml file that is
output from a servlet.
 There is no text in the table.
Imagine a test that has 500 questions and each cell in the table
represents a question - they are red/green/grey square jpeg's depeding
on if you got the question correct/incorrect or n/a (you didn't answer
it)
 Ideally you'd end up with alot of green squares and a few red squares
- then you could click on any square and the page would update with a
box at the bottom showing you all the details of that question.
I have pasted some simple xslt code below (it doesn't include all the
elements or features - it is just for testing purposes)  that goes
through each element in the xml file and makes a row for it in the
table. I'm having problems figuring out how to automatically make
multiple rows and columns with data like this - obviously a simple
foreach loop won't work. All the data is the same - it is just in a
table to structure it for ease of viewing so columns and rows don't
actually map to anything - it's all the same. The other problem is
that a user may not answer all the questions and can only answer some
of them - meaning there is not guarranteed to be 500 elements in the
xml file.
 Maybe a table isn't the best structure to use in this case?
Any advice?


<xsl:template match="/">

    <HTML>

    <BODY>

    <TABLE BORDER="0" CELLSPACING="0" WIDTH="80%">

    <xsl:for-each select="testresults/test">

    <TR>
       <xsl:choose>
        <xsl:when test="result &gt; 0">
        <TD>
        <a href="{plot_path}" target="_blank">
         <IMG SRC="red.jpg"/>
        </a>
        </TD>
        </xsl:when>

        <xsl:when test="result = 0">
        <TD>
        <a href="{plot_path}" target="_blank">
         <IMG SRC="green.jpg"/>
        </a>
        </TD>
        </xsl:when>
        <xsl:otherwise>
        <TD>
        <a href="{plot_path}" target="_blank">
         <IMG SRC="grey.jpg"/>
        </a>
        </TD>
        </xsl:otherwise>
       </xsl:choose>
    </TR>
    </xsl:for-each>
    </TABLE>
     </BODY>
    </HTML>
    </xsl:template>
</xsl:stylesheet>

Current Thread