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

  • Home
  • SEARCH
  • 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 3405490
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T05:30:43+00:00 2026-05-18T05:30:43+00:00

For a given xml, I need to generate a html table to represent the

  • 0

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>
  • 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-05-18T05:30:43+00:00Added an answer on May 18, 2026 at 5:30 am

    This stylesheet:

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
        <xsl:template match="/*//*[1]">
            <table border="1">
                <xsl:call-template name="makeRow"/>
            </table>
        </xsl:template>
        <xsl:template match="*" name="makeRow">
            <tr>
                <td>
                    <xsl:value-of select="name()"/>
                </td>
                <td>
                    <xsl:apply-templates select="node()[1]"/>
                </td>
            </tr>
            <xsl:apply-templates select="following-sibling::node()[1]"/>
        </xsl:template>
        <xsl:template match="/*">
            <xsl:apply-templates select="node()[1]"/>
        </xsl:template>
    </xsl:stylesheet>
    

    Output:

    <table border="1">
        <tr>
            <td>key1</td>
            <td> Text Value  </td>
        </tr>
        <tr>
            <td>key2</td>
            <td>
                <table border="1">
                    <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 </td>
        </tr>
    </table>
    

    Note: This use the fine grained traversal patter. Three rules: “first child descendant of root element”, output table and call makeRow; makeRow (match any element not being the first child descendant nor root element) output tr and table cells with name and first child applycation, then apply templates to next sibling; root element rule, start the fine grained traversal.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a tool to generate WiX XML given a .reg file? In 2.0,
Given the following XML I need to place the contents of the suffix tag
I need to generate a number of XML documents from Java objects. The objects
Alright, so here is my issue. I need to generate xml in Java to
I've followed the steps given in the Android Developer Blog to generate a build.xml
I'm trying to generate XML that will output the structure and data of any
I have an XML file, I need to extract values from it, and put
Say I have this given XML file: <root> <node>x</node> <node>y</node> <node>a</node> </root> And I
Given this XML, what XPath returns all elements whose prop attribute contains Foo (the
Given this XML ... <ListBucketResult xmlns=http://s3.amazonaws.com/doc/2006-03-01/> <Name>public.rpmware.com</Name> <Prefix></Prefix> <Marker></Marker> <MaxKeys>1000</MaxKeys> <IsTruncated>false</IsTruncated> <Contents> <Key>0.dir</Key> <LastModified>2008-06-25T16:09:49.000Z</LastModified>

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.