Reposting to a more relevant group.
I am passing a generic dataset into a new XMLDataDocument and then
parsing the XML with XSLT. The idea being that I can parse any dataset
with the same xslt, and dynamically generate an html table. The problem
is when the DataSet contains a null value, the node for that record is
not created. Then when the xml parses it, there are too few cells in
some of the table rows.
I can think of a couple of ways of solving this, in theory:
1. Before I pass the dataset to the XMLDataDocument, I can replace every
null field with an empty string.
2. Come up with some zippy xsl that knows when a node is missing.
A possible third solution: Maybe there's a way of telling the
XMLDataDocument to render nodes even if the value is null?
In practice, I can't come up with a way of actually doing any of these.
Here's a bit of code:
c#
ds is a DataSet containing one table with several columns and rows
ds.DataSetName = "foo";
ds.Tables[0].TableName = "bar";
XmlDataDocument xmlDoc = new XmlDataDocument(ds);
XSLT
<table>
<tr>
<xsl:for-each select="/foo/bar[1]/*">
<th><xsl:value-of select="translate(name(.),'_',' ')"/></th>
</xsl:for-each>
</tr>
<xsl:for-each select="/foo/bar">
<tr>
<xsl:for-each select="*">
<td><xsl:value-of select="." /></td>
</xsl:for-each>
</tr>
</xsl:for-each>
</table>
The actual xslt is a bit more involved than that - otherwise I'd just be
using a datagrid object. But you get the idea.
any ideas?
-ivan.