Subject: Re: [xsl] oracle table to html via xsl From: Matt Gushee <mgushee@xxxxxxxxxxxxx> Date: Wed, 24 Apr 2002 03:37:57 -0600 |
On Wed, Apr 24, 2002 at 09:54:12AM +0100, Denis McCarthy wrote: > I'm trying to develop an xsl to convert an xml stream to a generic html > table. The xml I produce comes from an oracle database. The xml I produce > looks like this: > <results> > <numberOfRows>n</numberOfRows> > <record> > <columnName>colName1</columnName> > <columnValue>colValue1</colValue> > <columnName>colName2</columnName> > <columnValue>colValue2</colValue> > <columnName>colName3</columnName> > <columnValue>colValue3</colValue> > etc... > </record> > <record> > etc... > </record> > I would like the xsl to convert the <colName>s into <th>'s and align the > <colValue>s appropriately under the correct <th>. > I have managed this, but I had to insert the columnNames seperate from the > columnValues at the top of the xml to get it working. I would prefer if I > could keep the column names in the <record> tag (it seems more xml-esque) Why? Because it's more verbose? ;-) Here's how I would probably do that: <!-- within template matching "results" --> <xsl:apply-templates select="record[1]" mode="header"/> <xsl:apply-templates select="record"/> <!-- and then ... --> <xsl:template match="record" mode="header"> <tr> <xsl:apply-templates select="columnName"/> </tr> </xsl:template> <xsl:template match="columnName"> <th> <xsl:value-of select="."/> </th> </xsl:template> <xsl:template match="record"> <tr> <xsl:apply-templates select="columnValue"/> </tr> </xsl:template> <xsl:template match="columnValue"> <td> <xsl:value-of select="."/> </td> </xsl:template> Now, this assumes that every record contains elements representing all fields. If that's not the case things become a little more complex. I suppose then you would want to do something with <xsl:key/> ... I'd have to think about that a bit more. -- Matt Gushee Englewood, Colorado, USA mgushee@xxxxxxxxxxxxx http://www.havenrock.com/ XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] oracle table to html via xsl, Denis McCarthy | Thread | [xsl] regarding xpath, william locksman |
RE : [xsl] (text processing) lexica, Nicolas Mazziotta | Date | [xsl] regarding xpath, william locksman |
Month |