Subject: Re: [xsl] XML->HTML tables with blank cells ... From: "Mukul Gandhi" <gandhi.mukul@xxxxxxxxx> Date: Tue, 11 Jul 2006 14:54:18 +0530 |
I thought you might be needing a generic solution (when number of columns are variable).
<?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/worksheet"> <html> <head> <title/> </head> <body> <table> <tr> <xsl:for-each select="row[@number = '0']/col"> <th><xsl:value-of select="." /></th> </xsl:for-each> </tr> <xsl:variable name="n" select="count(row[@number = '0']/col) - 1" /> <xsl:for-each select="row[not(@number = '0')]"> <tr> <xsl:call-template name="GenerateRows"> <xsl:with-param name="m" select="$n" /> <xsl:with-param name="n" select="$n" /> <xsl:with-param name="row" select="." /> </xsl:call-template> </tr> </xsl:for-each> </table> </body> </html> </xsl:template>
<xsl:template name="GenerateRows"> <xsl:param name="m" /> <xsl:param name="n" /> <xsl:param name="row" />
<xsl:if test="$m >= 0"> <td><xsl:value-of select="$row/col[@number = ($n - $m)]" /></td> <xsl:call-template name="GenerateRows"> <xsl:with-param name="m" select="$m - 1" /> <xsl:with-param name="n" select="$n" /> <xsl:with-param name="row" select="$row" /> </xsl:call-template> </xsl:if> </xsl:template>
Regards, Mukul
Hello.
I'm very new to XSLT and I need to create an HTML table from XML using XSLT. The XML looks like this:
<?xml version="1.0" encoding="UTF-8"?> <worksheet> <row number="0"> <col number="0">Name</col> <col number="1">Grade</col> <col number="2">Phone</col> <col number="3">City</col> <col number="4">State</col> </row> <row number="1"> <col number="0">Anna</col> <col number="1">3</col> <col number="2">555-5555</col> <col number="3">Livermore</col> <col number="4">CA</col> </row> <row number="2"> <col number="0">David</col> <col number="1">4</col> <col number="3">Livermore</col> <col number="4">CA</col> </row> <row number="3"> <col number="0">Jane</col> <col number="1">5</col> </row> </worksheet>
I want a resulting HTML table that accounts for the fact that every piece of data is in the correct column but not every row has data in all columns. For example, in my example, Anna has all data, but David does not have a phone number, and Jane only has a grade.
Thanks for you help.
Carmen
--------------------------------------------------------------------- Carmen Pancerella, PhD carmen@xxxxxxxxxxxxx Distributed Systems Research & Development Sandia National Laboratories ---------------------------------------------------------------------
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] XML->HTML tables with bla, Mukul Gandhi | Thread | [xsl] Problem with empty element ch, Shamik Bandopadhyay |
Re: [xsl] Text Wrapping problem wit, Mukul Gandhi | Date | RE: [xsl] Text Wrapping problem wit, Rick Roen |
Month |