I have a table structure like this:
| id | name | parent_id |
|---|---|---|
| 1 | root_category | Null |
| 2 | Appare | 1 |
| 3 | Accessories | 1 |
| 4 | Shirt | 2 |
| 5 | Pants | 2 |
| 6 | hand Bags | 3 |
| 7 | jewelry | 3 |
from this table I have created a XML file which is like this test.xml
<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/xsl" href="test.xsl"?>
<childrens>
<child id="1" value="Root Catalog" parent_id="0">
<child id="2" value="Apparel" parent_id="1">
<child id="4" value="Shirts" parent_id="2"/>
<child id="5" value="Pants" parent_id="2"/>
</child>
<child id="3" value="Accessories" parent_id="1">
<child id="6" value="Handbags" parent_id="3"/>
<child id="7" value="Jewelry" parent_id="3"/>
</child>
</child>
</childrens>
using this xml file i have created a XSL file which is like this test.xsl
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<h2>Testing</h2>
<table border="1">
<tr bgcolor="#9acd32">
<th>Id </th>
<th>Name</th>
</tr>
<xsl:for-each select="childrens/child">
<tr>
<td><xsl:value-of select="@id"/></td>
<td><xsl:value-of select="@value"/></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
but it is not working and it is not showing data
data should look like
Root Category
- Apparel
-- Shirts
-- Pants
- Accessories
-- Handbags
-- Jewelry
I am not entirely sure what output you are expecting. Your current XSLT is outputing a table, but your example looks more like nested lists. If you did want to show the hierarchy structure of your elements, then nested lists would probably be the way to go.
This would be relatively straight-forward to achieve by means of a single template to match child elements, which then recursively called itself.
i.e. Output a li element, and then start a new ul element within this if the element itself has children.
Here is the full XSLT
When applied to your sample XML, the following is output
Which visually will appear as follows
EDIT: As mentioned by JLRishie in the comment (Thanks!), if you want to include the ID attribute on the li elements, do the following: