XSL Transform Tree into Table

D

Daniel Hirscher

Hi,

I like to transform a XML hierarchical tree structure into a HTML
Table.
All leaves are on the same depth of the tree. Every tree will give a
correct table without empty cells. The number of elements in one
hierarchy level can be more than two.

My problem is that I have to go into tree-depth and table-width at the
same time. Calculation of colspan is no problem.

How can I solve this recursively?

Example:

XML look like this:

<tree>
<sub name="1">
<sub name="2">
<sub name="3"/>
<sub name="4"/>
</sub>
<sub name="5">
<sub name="6"/>
<sub name="7"/>
</sub>
</sub>
<sub name="8">
<sub name="9">
<sub name="10"/>
<sub name="11"/>
</sub>
<sub name="12">
<sub name="13"/>
<sub name="14"/>
</sub>
</sub>
</tree>

HTML should look like this:

<table border="1">
<tr>
<td colspan="4">1</td>
<td colspan="4">8</td>
</tr>
<tr>
<td colspan="2">2</td>
<td colspan="2">5</td>
<td colspan="2">9</td>
<td colspan="2">12</td>
</tr>
<tr>
<td>3</td>
<td>4</td>
<td>6</td>
<td>7</td>
<td>10</td>
<td>11</td>
<td>13</td>
<td>14</td>
</tr>
</table>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,226
Members
46,815
Latest member
treekmostly22

Latest Threads

Top