For a given xml, I need to generate a html table to represent the values in the xml.
I need the recursion for any keyN, if valueN is text then just print it. If valueN is xml, then print a (nested)table with it’s value. I think my lack of understanding of how to use XSLT recursion correctly is the base of the question. Any help appreciated.
Input:
<root>
<key1> Text Value </key1>
<key2>
<a> aaa </a>
<b> bbb </b>
</key2>
<keyN> valueN </keyN>
<root>
Output:
<table border="1px">
<tr>
<td> key1 </td>
<td> Text Value </td>
</tr>
<tr>
<td> key2 </td>
<td>
<table border="1px">
<tr> <td> a </td> <td> aaa </td> </tr>
<tr> <td> b </td> <td> bbb </td> </tr>
</table>
</td>
</tr>
<tr>
<td> keyN </td>
<td>
valueN (if valueN is text)
OR
<table> ... </table> (if valueN is xml)
<td>
</tr>
</table>
This stylesheet:
Output:
Note: This use the fine grained traversal patter. Three rules: “first child descendant of root element”, output
tableand callmakeRow;makeRow(match any element not being the first child descendant nor root element) outputtrand table cells with name and first child applycation, then apply templates to next sibling; root element rule, start the fine grained traversal.