Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9175881
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T16:59:20+00:00 2026-06-17T16:59:20+00:00

I have a table structure like this: id name parent_id 1 root_category Null 2

  • 0

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
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T16:59:21+00:00Added an answer on June 17, 2026 at 4:59 pm

    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.

       <xsl:template match="child">
          <li>
             <xsl:value-of select="@value"/>
             <xsl:if test="child">
                <ul>
                   <xsl:apply-templates select="child"/>
                </ul>
             </xsl:if>
          </li>
       </xsl:template>
    

    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

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
       <xsl:output method="html" indent="yes"/>
    
       <xsl:template match="/childrens">
          <html>
             <body>
                <ul>
                   <xsl:apply-templates select="child"/>
                </ul>
             </body>
          </html>
       </xsl:template>
    
       <xsl:template match="child">
          <li>
             <xsl:value-of select="@value"/>
             <xsl:if test="child">
                <ul>
                   <xsl:apply-templates select="child"/>
                </ul>
             </xsl:if>
          </li>
       </xsl:template>
    </xsl:stylesheet>
    

    When applied to your sample XML, the following is output

    <html>
       <body>
          <ul>
             <li>Root Catalog
                <ul>
                   <li>Apparel
                      <ul>
                         <li>Shirts</li>
                         <li>Pants</li>
                      </ul>
                   </li>
                   <li>Accessories
                      <ul>
                         <li>Handbags</li>
                         <li>Jewelry</li>
                      </ul>
                   </li>
                </ul>
             </li>
          </ul>
       </body>
    </html>
    

    Which visually will appear as follows

    • Root Catalog
      • Apparel
        • Shirts
        • Pants
      • Accessories
        • Handbags
        • Jewelry

    EDIT: As mentioned by JLRishie in the comment (Thanks!), if you want to include the ID attribute on the li elements, do the following:

    <li id="{@id}">
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an table structure like this mysql> SELECT id, name, parent_id FROM categories;
I have a table structure with columns like this [ID] [Name] [ParentId] [ParentName] The
I have a MySQL table structured somewhat like this: type name value ===================== 1
I have a table structure like this: <table> <tr> <td> <ul> <li class=check></li> </ul>
I have my Table structure like this :: ATT_Table : Fields - Act_ID, Assigned_To_ID,
If I have a table structure like this: Transaction [TransID, ...] Document [DocID, TransID,
My table have data structure like this cate_id task_id date_start date_end other 34 14
We have a table with tree structure like this: Id Desc ParentID === A
I have a 'users' SQL table structure like this (the ID is randomly generated
I have a 'users' SQL table structure like this (the ID is randomly generated,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.