I’ve got some hierarchical XML like this:
<node text="a" value="1">
<node text="gga" value="5">
<node text="dh" value="9">
<node text="tyfg" value="4">
</node>
</node>
</node>
<node text="dfhgf" value="7">
<node text="fdsg" value="2">
</node>
</node>
</node>
The names of the elements are the same all the way down (“node”), and the depth of the hierarchy isn’t known beforehand – in the above sample the deepest leaf is four down, but it can be of any depth.
What I need to do is take this XML and flatten it into a HTML table. The number of columns in the table should equal the depth of the deepest element, plus a column for the value attribute of each element. The "value" should appear in the rightmost column of the table, so the output rows cannot have ragged edges. There should be a row for each node regardless of what level it’s at. The above example should be transformed into:
<table>
<tr>
<td>a</td>
<td></td>
<td></td>
<td></td>
<td>1</td>
</tr>
<tr>
<td>a</td>
<td>gga</td>
<td></td>
<td></td>
<td>5</td>
</tr>
<tr>
<td>a</td>
<td>gga</td>
<td>dh</td>
<td></td>
<td>9</td>
</tr>
<tr>
<td>a</td>
<td>gga</td>
<td>dh</td>
<td>tyfg</td>
<td>4</td>
</tr>
<tr>
<td>a</td>
<td>dfhgf</td>
<td></td>
<td></td>
<td>7</td>
</tr>
<tr>
<td>a</td>
<td>dfhgf</td>
<td>fdsg</td>
<td></td>
<td>2</td>
</tr>
</table>
Anybody got some clever XSLT that can achieve this?