Subject: Re: [xsl] creating a table with xslt From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx> Date: Mon, 17 Mar 2008 11:46:35 -0400 |
<xsl:for-each select="testresults/test[position() mod 20 = 1]"> <!-- select every 20th 'test' element, that is, #s 1, 21, 41, etc. --> <tr> <xsl:for-each select=".|following-sibling[position() < 20]"> <!-- now select the current 'test' element plus its 19 nearest following siblings --> ... <td> <!-- making a cell for each of these --> ... </td> </xsl:for-each> </tr> </xsl:for-each>
<TD> <a href="{plot_path}" target="_blank"> <xsl:choose> <xsl:when test="result > 0"> <IMG SRC="red.jpg"/> <xsl:when> <xsl:when test="result = 0"> <IMG SRC="green.jpg"/> </xsl:when> ... etc.
<xsl:template match="result[. > 0]"> <IMG SRC="red.jpg"/> <xsl:template>
<xsl:template match="result[. = 0]"> <IMG SRC="green.jpg"/> <xsl:template>
... <TD> <a href="{plot_path}" target="_blank"> <xsl:apply-templates select="result"/> </a> </TD> ...
Cheers, Wendell
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 > 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>
====================================================================== Wendell Piez mailto:wapiez@xxxxxxxxxxxxxxxx Mulberry Technologies, Inc. http://www.mulberrytech.com 17 West Jefferson Street Direct Phone: 301/315-9635 Suite 207 Phone: 301/315-9631 Rockville, MD 20850 Fax: 301/315-8285 ---------------------------------------------------------------------- Mulberry Technologies: A Consultancy Specializing in SGML and XML ======================================================================
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] creating a table with xslt, Kimberly Begley | Thread | [xsl] general question about an app, Andreas Peter |
Re: [xsl] Grouping simple flat stru, Andrew Welch | Date | [xsl] Normalizar una ontologia, igutierrez027 |
Month |