xsl-list
[Top] [All Lists]

Re: [xsl] XML->HTML tables with blank cells ...

2006-07-11 00:11:41
Hi Carmen,
 Please try this stylesheet:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>

<xsl:output method="html" indent="yes" />

<xsl:template match="/worksheet">
  <html>
    <head>
      <title/>
    </head>
    <body>
      <table>
        <tr>
          <th><xsl:value-of select="row[(_at_)number = '0']/col[(_at_)number =
'0']" /></th>
          <th><xsl:value-of select="row[(_at_)number = '0']/col[(_at_)number =
'1']" /></th>
          <th><xsl:value-of select="row[(_at_)number = '0']/col[(_at_)number =
'2']" /></th>
          <th><xsl:value-of select="row[(_at_)number = '0']/col[(_at_)number =
'3']" /></th>
          <th><xsl:value-of select="row[(_at_)number = '0']/col[(_at_)number =
'4']" /></th>
        </tr>
        <xsl:for-each select="row[not(@number = '0')]">
          <tr>
            <td><xsl:value-of select="col[(_at_)number = '0']" /></td>
            <td><xsl:value-of select="col[(_at_)number = '1']" /></td>
            <td><xsl:value-of select="col[(_at_)number = '2']" /></td>
            <td><xsl:value-of select="col[(_at_)number = '3']" /></td>
            <td><xsl:value-of select="col[(_at_)number = '4']" /></td>
          </tr>
        </xsl:for-each>
      </table>
    </body>
  </html>
</xsl:template>

</xsl:stylesheet>

The output produced is:

<html>
  <head>
     <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
     <title></title>
  </head>
  <body>
     <table>
        <tr>
           <th>Name</th>
           <th>Grade</th>
           <th>Phone</th>
           <th>City</th>
           <th>State</th>
        </tr>
        <tr>
           <td>Anna</td>
           <td>3</td>
           <td>555-5555</td>
           <td>Livermore</td>
           <td>CA</td>
        </tr>
        <tr>
           <td>David</td>
           <td>4</td>
           <td></td>
           <td>Livermore</td>
           <td>CA</td>
        </tr>
        <tr>
           <td>Jane</td>
           <td>5</td>
           <td></td>
           <td></td>
           <td></td>
        </tr>
     </table>
  </body>
</html>

Regards,
Mukul

On 7/11/06, Carmen Pancerella <carmen(_at_)ca(_dot_)sandia(_dot_)gov> wrote:
Hello.

I'm very new to XSLT and I need to create an HTML table from XML
using XSLT.  The XML looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<worksheet>
   <row number="0">
     <col number="0">Name</col>
     <col number="1">Grade</col>
     <col number="2">Phone</col>
     <col number="3">City</col>
     <col number="4">State</col>
   </row>
   <row number="1">
     <col number="0">Anna</col>
     <col number="1">3</col>
     <col number="2">555-5555</col>
     <col number="3">Livermore</col>
     <col number="4">CA</col>
   </row>
   <row number="2">
     <col number="0">David</col>
     <col number="1">4</col>
     <col number="3">Livermore</col>
     <col number="4">CA</col>
   </row>
   <row number="3">
     <col number="0">Jane</col>
     <col number="1">5</col>
   </row>
</worksheet>

I want a resulting HTML table that accounts for the fact that every
piece of data is in the correct column but not every row has data
in all columns.  For example, in my example, Anna has all data,
but David does not have a phone number, and Jane only has a grade.

Thanks for you help.

Carmen

---------------------------------------------------------------------
Carmen Pancerella, PhD  carmen(_at_)ca(_dot_)sandia(_dot_)gov
Distributed Systems Research & Development
Sandia National Laboratories

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>