Re: [xsl] Create Table

Subject: Re: [xsl] Create Table
From: bernie bonn <moochambo@xxxxxxxxx>
Date: Mon, 22 Mar 2010 12:57:04 -0700 (PDT)
HI Eric & List,

Thanks for this solution.B  There is another gotcha.B  I
realized I didn't make clearthat, all the changes are inside of one parent
elementB  <interface-categories name='Source Changes' category='Source'>.
So I
need to switch on <data> children inside of that.B  How I know it is the start
of a new change and table row,B is the data node will have the attribute
'changes'B  <data section='changes'
field='file'>ConvertHistoryWages.java</data>.B  There can be mutliple
'changes' inside the parent element <interface-changes>.B  
I apologize, for
not being clear.B  Any additional guidance is sure appreciated. 

Thanks.,
Bernie

B 


----- Original Message ----
From: Eric J. Bowman
<eric@xxxxxxxxxxxxxxxx>
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Cc: bernie bonn
<moochambo@xxxxxxxxx>
Sent: Sat, March 20, 2010 5:06:36 PM
Subject: Re: [xsl]
Create Table

bernie bonn wrote:
> B 
> There are a series of data nodes that
represent either headings or
> bdiffsb or detail to the headings. The
headings are denoted by the
> attribute section=bchangesb.B  Basically,
B every time I encounter this
> section I want to make a new table row and
fill the cells with the
> different value of the element, or I could even
create a whole new
> table.
>

I've given a solution which includes <tbody>
elements, you can
extrapolate that into different tables if needed.

>
> The
problem I am having is testing if a fild is missing, some
> entries don't have
a field="file for example.B  In that case I have to
> leave a blank cell.
>
Using a recursive push solution is best for building the structure of
the
tables, while filling the cells in your case calls for a pull
solution.B  I
mocked up a source file that isn't an exact fit, but does
illustrate your
issue, that's listed first, followed by the XSLT.

My thinking, obviously, is
that an extra nbsp doesn't hurt anything.

HTH,
Eric

<?xml version='1.0'
encoding='utf-8'?>
<server-manifest>
B  B  <category-source>
B  B  B  B 
<interface-categories name='Source Changes' category='Source'>
B  B  B  B  B 
B  <data section='diff'>if (reportService != null)</data>
B  B  B  B  B  B 
<data section='diff'>return true;</data>
B  B  B  B  B  B  <data
section='diff'>return false;</data>
B  B  B  B  B  B  <data section='changes'
field='file'>ConvertHistoryWages.java</data>
B  B  B  B  B  B  <data
section='changes' field='version'>\main\spr2010_apr_dev\2</data>
B  B  B  B 
B  B  <data section='changes' field='date'>20100310.102844</data>
B  B  B  B 
B  B  <data section='changes' field='user'>jryan</data>
B  B  B  B  B  B 
<data section='changes' field='cr_number'>602018</data>
B  B  B  B  B  B 
<data section='changes' field='comment'>fix for log 5960</data>
B  B  B  B  B 
B  <data section='diff'>1296a1297,1298</data>
B  B  B  B  B  B  <data
section='diff'></data>
B  B  B  B  </interface-categories>
B  B  B  B 
<interface-categories name='Source Changes' category='Source'>
B  B  B  B  B 
B  <data section='diff'>if (reportService != null)</data>
B  B  B  B  B  B 
<data section='diff'>return true;</data>
B  B  B  B  B  B  <data
section='diff'>return false;</data>
B  B  B  B  B  B  <data section='changes'
field='file'>ConvertHistoryWages.java</data>
B  B  B  B  B  B  <data
section='changes' field='version'>\main\spr2010_apr_dev\2</data>
B  B  B  B 
B  B  <data section='changes' field='date'>20100310.102844</data>
B  B  B  B 
B  B  <data section='changes' field='cr_number'>602018</data>
B  B  B  B  B 
B  <data section='changes' field='comment'>fix for log 5960</data>
B  B  B  B 
B  B  <data section='diff'>1296a1297,1298</data>
B  B  B  B  B  B  <data
section='diff'></data>
B  B  B  B  </interface-categories>
B  B 
</category-source>
B  B  <category-source>
B  B  B  B  <interface-categories
name='Source Changes' category='Source'>
B  B  B  B  B  B  <data
section='diff'>if (reportService != null)</data>
B  B  B  B  B  B  <data
section='diff'>return true;</data>
B  B  B  B  B  B  <data
section='diff'>return false;</data>
B  B  B  B  B  B  <data section='changes'
field='file'>ConvertHistoryWages.java</data>
B  B  B  B  B  B  <data
section='changes' field='date'>20100310.102844</data>
B  B  B  B  B  B  <data
section='changes' field='user'>jryan</data>
B  B  B  B  B  B  <data
section='changes' field='cr_number'>602018</data>
B  B  B  B  B  B  <data
section='diff'>1296a1297,1298</data>
B  B  B  B  B  B  <data
section='diff'></data>
B  B  B  B  </interface-categories>
B  B 
</category-source>
</server-manifest>

<?xml version='1.0' encoding='utf-8'?>
<xsl:stylesheet version='1.0'
B  B  xmlns='http://www.w3.org/1999/xhtml'
B  B 
xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>
B  B  <xsl:output
omit-xml-declaration='no' method='xml' indent='yes' xml:space='default'
encoding='utf-8'/>
B  B  <xsl:template match='/'>
B  B  B  B  <html
xmlns='http://www.w3.org/1999/xhtml' xml:lang='en'>
B  B  B  B  B  B  <head>
B  B  B  B  B  B  B  B  <title>table example</title>
B  B  B  B  B  B  B  B 
<style type='text/css'>table{table-layout:fixed;width:auto}</style>
B  B  B 
B  B  B  </head>
B  B  B  B  B  B  <body>
B  B  B  B  B  B  B  B  <table
width='0' summary='summary goes here for accessibility'>
B  B  B  B  B  B  B 
B  B  B  <caption>caption goes here for accessibility</caption>
B  B  B  B  B 
B  B  B  B  B  <thead>
B  B  B  B  B  B  B  B  B  B  B  B  <tr>
B  B  B  B  B 
B  B  B  B  B  B  B  B  B  <th scope='col'>File</th>
B  B  B  B  B  B  B  B 
B  B  B  B  B  B  <th scope='col'>Version</th>
B  B  B  B  B  B  B  B  B  B 
B  B  B  B  <th scope='col'>Date</th>
B  B  B  B  B  B  B  B  B  B  B  B  B 
B  <th scope='col'>User</th>
B  B  B  B  B  B  B  B  B  B  B  B  B  B  <th
scope='col'>CR Number</th>
B  B  B  B  B  B  B  B  B  B  B  B  B  B  <th
scope='col'>Comment</th>
B  B  B  B  B  B  B  B  B  B  B  B  </tr>
B  B  B  B 
B  B  B  B  B  B  </thead>
B  B  B  B  B  B  B  B  B  B  <tfoot><!-- optional
-->
B  B  B  B  B  B  B  B  B  B  B  B  <tr>
B  B  B  B  B  B  B  B  B  B  B 
B  B  B  <th>File</th>
B  B  B  B  B  B  B  B  B  B  B  B  B  B 
<th>Version</th>
B  B  B  B  B  B  B  B  B  B  B  B  B  B  <th>Date</th>
B  B 
B  B  B  B  B  B  B  B  B  B  B  B  <th>User</th>
B  B  B  B  B  B  B  B  B 
B  B  B  B  B  <th>CR Number</th>
B  B  B  B  B  B  B  B  B  B  B  B  B  B 
<th>Comment</th>
B  B  B  B  B  B  B  B  B  B  B  B  </tr>
B  B  B  B  B  B 
B  B  B  B  </tfoot>
B  B  B  B  B  B  B  B  B  B  <xsl:apply-templates
select='//category-source'/>
B  B  B  B  B  B  B  B  </table>
B  B  B  B  B 
B  </body>
B  B  B  B  </html>
B  B  </xsl:template>
B  B  <xsl:template
match='category-source'>
B  B  B  B  <tbody><xsl:apply-templates
select='./interface-categories'/></tbody>
B  B  </xsl:template>
B  B 
<xsl:template match='interface-categories'>
B  B  B  B  <tr>
B  B  B  B  B  B 
<td scope='row'><xsl:value-of select="./data[@field='file']"/>B </td>
B  B  B 
B  B  B  <td><xsl:value-of select="./data[@field='version']"/>B </td>
B  B  B 
B  B  B  <td><xsl:value-of select="./data[@field='date']"/>B </td>
B  B  B  B 
B  B  <td><xsl:value-of select="./data[@field='user']"/>B </td>
B  B  B  B  B 
B  <td><xsl:value-of select="./data[@field='cr_number']"/>B </td>
B  B  B  B 
B  B  <td><xsl:value-of select="./data[@field='comment']"/>B </td>
B  B  B  B 
</tr>
B  B  </xsl:template>
</xsl:stylesheet>

Current Thread