How to use XSL to transpose tables and rows

Posted on 2005-04-12
Last Modified: 2008-03-03

A colleague gave me an XML file similar to the following:

       <report_date>5 April 2005</report_date>
       <report_date>12 April 2005</report_date>

I know how to use XSL to put this in a table as follows:

Report Date    Shipments     Invoices    Claims
5 April 2005        503              500          26
12 April 2005      496              496          18

But he would like the rows and columns transposed--i.e.,

Report Date       5 April 2005      12 April 2005
Shipments               503                  496
Invoices                   500                  496
Claims                      26                    18

Is there an easy way to do this with XSL while still keeping the current structure of the XML file?  If not, is there a difficult way? ;)  or some other option (like JavaScript)?

Many thanks--

Question by:KathrynGZ
    LVL 15

    Accepted Solution

    yes, why not :)
    it's rahter easy, for instance this one:

    <?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet version="1.0" xmlns:xsl="">
          <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
          <xsl:template match="/">

                                  <td>Report Date:</td>
                                  <xsl:apply-templates select="/reports/weekly_report/report_date" />
                                  <xsl:apply-templates select="/reports/weekly_report/shipments" />
                                  <xsl:apply-templates select="/reports/weekly_report/invoices" />
                                  <td>Claims: </td>
                                  <xsl:apply-templates select="/reports/weekly_report/claims" />
          <xsl:template match="report_date | shipments | invoices | claims">
                <td><xsl:value-of select="." /></td>

    Author Comment

    Perfect!! Worked exactly as needed the first time. To say thanks, I added an extra 25 points :)

    LVL 15

    Expert Comment


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Enabling OSINT in Activity Based Intelligence

    Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

    Suggested Solutions

    Introduction In my previous article ( I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
    I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
    This video discusses moving either the default database or any database to a new volume.
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now