[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: Generating Table Cell values to match Columns

Subject: RE: Generating Table Cell values to match Columns
From: "Passin, Tom" <tpassin@xxxxxxxxxxxx>
Date: Tue, 18 Mar 2003 17:43:45 -0500
match columns
[ Glenn Copen]
> 
> I have table data that may have blank entries for specific 
> cells. 

[snipped xml]
> How do I generate the <TD> element for the matching column in XSLT?  I
> need to somehow test the value of "colname" in <entry> against the
> "colname" in the <colspec>.
> 
> This needs to be a "generic" solution based on the XML data, 
> since I have
> many tables in the file with different number of columns, different
> colname values, etc.

As long as all column names and entries are unique, it is easy.  Here is
a solution using xsl:for-each to generate the header row and then to
work through each row.  For each column name, the xpath expression finds
the cell that matches the name, if there is one.  (I have omitted some
of the HTML elements for simplicity, but the result is still valid
HTML).

You may want to fancy it up  some, possibly testing for missing content,
but this should get you started.

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method='html'/>

<xsl:variable name='column-names'
select='table/thead/colspec/@colname'/>

<xsl:template match="/table">
<table border='1'>
   <tr>
      <xsl:for-each select='$column-names'>
         <th><xsl:value-of select='.'/></th>
      </xsl:for-each>
   </tr>
   <xsl:apply-templates select='tbody/row'/>
</table>
</xsl:template>

<xsl:template match='row'>
   <xsl:variable name='entries' select='entry'/>
   <tr>
      <xsl:for-each select='$column-names'>
         <td><xsl:value-of select='$entries[@colname =
current()]'/></td>
      </xsl:for-each>
   </tr>
</xsl:template>

</xsl:stylesheet>

Cheers,

Tom P

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.