This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: oracle table to html via xsl
- From: Matt Gushee <mgushee at havenrock dot com>
- To: xsl-list at lists dot mulberrytech dot com
- Date: Wed, 24 Apr 2002 03:37:57 -0600
- Subject: Re: [xsl] oracle table to html via xsl
- References: <05b101c1eb6d$9b062b80$bb00a8c0@dmccarthy>
- Reply-to: xsl-list at lists dot mulberrytech dot com
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@havenrock.com
http://www.havenrock.com/
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list