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 6933921
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T11:53:39+00:00 2026-05-27T11:53:39+00:00

I would like to transform an XML document using xslt with a set of

  • 0

I would like to transform an XML document using xslt with a set of row nodes and column nodes into an xhtml table.

The column nodes define data about the associated row attribute. For example, the first column node specifies that the ID attribute of the Row node should be hidden (i.e. not show up in the table). The Caption element of the Column node defines what the column header text should be.

I’ve seen solutions where you know the attributes that you want to turn into columns ahead of time, but I’m not sure how to use the relevant column data to format the headers

Input:

<TableData>
    <Columns>
         <Column Name="ID" Hidden="true" />
         <Column Name="Name" Caption="Item Name" />
         <Column Name="Desc" Caption="Item Description" />
    </Columns>
    <Rows>
         <Row ID="0" Name="A" />
         <Row ID="1" Name="B" Desc="Some description"/>
         <Row ID="3" Name="C" />
    </Rows>
</TableData>

Desired output would be a table in (x)html something like this:

Item Name      | Item Description
--------------------------------------
A              |      
B              | Some Description
C              |
  • 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-27T11:53:39+00:00Added an answer on May 27, 2026 at 11:53 am

    This transformation:

    <xsl:stylesheet version="1.0"
     xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
     <xsl:output omit-xml-declaration="yes" indent="yes"/>
    
     <xsl:key name="RowAttribsByName" match="Row/@*"
          use="concat(generate-id(..), '|', name())"/>
    
     <xsl:variable name="vColNames" select=
      "/*/Columns/*[not(@Hidden = 'true')]/@Name"/>
    
     <xsl:template match="/*">
      <table border="1">
        <tr>
         <xsl:apply-templates select="Columns/*"/>
        </tr>
        <xsl:apply-templates select="Rows/Row"/>
      </table>
     </xsl:template>
    
     <xsl:template match="Column[not(@Hidden = 'true')]">
      <td><xsl:value-of select="@Caption"/></td>
     </xsl:template>
    
     <xsl:template match="Row">
      <tr>
       <xsl:apply-templates select="$vColNames">
         <xsl:with-param name="pRowId"
              select="generate-id()"/>
       </xsl:apply-templates>
      </tr>
     </xsl:template>
    
     <xsl:template match="Column/@*">
      <xsl:param name="pRowId"/>
    
      <td width="50%">
        <xsl:value-of select=
          "key('RowAttribsByName',
               concat($pRowId, '|', .)
               )
        "/>
      </td>
     </xsl:template>
    </xsl:stylesheet>
    

    when applied on the provided XML document:

    <TableData>
        <Columns>
            <Column Name="ID" Hidden="true" />
            <Column Name="Name" Caption="Item Name" />
            <Column Name="Desc" Caption="Item Description" />
        </Columns>
        <Rows>
            <Row ID="0" Name="A" />
            <Row ID="1" Name="B" Desc="Some description"/>
            <Row ID="3" Name="C" />
        </Rows>
    </TableData>
    

    produces the wanted, correct result:

    <table border="1">
       <tr>
          <td>Item Name</td>
          <td>Item Description</td>
       </tr>
       <tr>
          <td width="50%">A</td>
          <td width="50%"/>
       </tr>
       <tr>
          <td width="50%">B</td>
          <td width="50%">Some description</td>
       </tr>
       <tr>
          <td width="50%">C</td>
          <td width="50%"/>
       </tr>
    </table>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using XSLT to convert a very large XML document into (X)HTML. For
Is it possible to use XSLT to transform XML into something other than XML?
Hi does anyone know what the xsl would look like to transform this XML.
In my C# client application, I use XSLT to transform XML into HTML. I
I have the following XML (partial) document : <export> <table name=CLIENT> <row> <col name=CODE_CLIENT
In my Python app, I have an XML document that I'd like to transform
I am new to XML, XSLT and SOAP and I would like to know
I'm trying to transform an XML document into another XML document. I've tried various
Would like to get a list of advantages and disadvantages of using Stored Procedures.
Would like to be able to set colors of headings and such, different font

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.