This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Dynamically building a HTML table from variable row data
- From: "Michael Leditschke" <ammd at bigpond dot net dot au>
- To: <XSL-List at lists dot mulberrytech dot com>
- Date: Sun, 16 Dec 2001 02:25:12 +1000
- Subject: [xsl] Dynamically building a HTML table from variable row data
- Reply-to: xsl-list at lists dot mulberrytech dot com
I am attempting to populate an HTML table
where the column names are generated by the
set of element names on each row. Not all
elements occur on all rows.
My problem is thus to dynamically work out
the total set of columns (using the element
names) and dynamically position each piece
of data in the correct column.
For example, assume XML looks like
<BLOCK>
<ROW>
<A>1</A>
<B>2</B>
</ROW>
<ROW>
<A>9</A>
<B>3</B>
<C>4</C>
</ROW>
<ROW>
<A>5</A>
<D>6</D>
<E>7</E>
</ROW>
<BLOCK>
I'd like to end up with a table something like
A B C D E
1 2
9 3 4
5 6 7
Thus far I have code something like
<xsl:template match="BLOCK">
<xsl:variable name="ColumnNames"
select="ROW/*[not(local-name()=local-name(preceding::ROW/*)))]"/>
<table border="10">
<tr>
<xsl:for-each select="$ColumnNames">
<th>
<xsl:value-of select="local-name()"/>
</th>
</xsl:for-each>
</tr>
</table>
</xsl:template>
I know its wrong because the local-name function is going
to process the first node only. So it handles the <A>
element ok but not any of the others.
I'm trying to follow the
examples I've seen of grouping but most seem to be based
on element/attribute content rather than element names.
Various wild and whacky schemes have come to mind but
before I looked for a zebra, I thought I'd check if anyone
knew of a horse.
Any pointers much appreciated.
Regards
Michael
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list