How to use XSL to transpose tables and rows


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--

Who is Participating?
dualsoulConnect With a Mentor Commented:
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>
KathrynGZAuthor Commented:
Perfect!! Worked exactly as needed the first time. To say thanks, I added an extra 25 points :)

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.