-----Original Message-----
From: Wolfgang Laun [mailto:wolfgang(_dot_)laun(_at_)gmail(_dot_)com]
Sent: 22 March 2010 09:29
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: Re: [xsl] Create Table
The table body can also be generated using an XPath
expression which avoids the spurious non-breaking space and
lets you specify attribute field's values in a sequence:
<tbody>
<!-- ... -->
<xsl:for-each
select="BOM/interface-categories/category[(_at_)category='Source']">
<tr>
<xsl:for-each select="for $x in
('file','version','date','user',
'cr_number','comment') return
if (data[(_at_)section='changes' and @field=$x]) then
data[(_at_)section='changes' and @field=$x] else
' '">
<td><xsl:value-of select="."/></td>
</xsl:for-each>
</tr>
</xsl:for-each>
</tbody>
-W
On Sat, Mar 20, 2010 at 10:06 PM, Eric J. Bowman
<eric(_at_)bisonsystems(_dot_)net> wrote:
bernie bonn wrote:
There are a series of data nodes that represent either headings or
?diffs? or detail to the headings. The headings are denoted by the
attribute section=?changes?. Basically, 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. 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. 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>
<category-source>
<interface-categories name='Source Changes'
category='Source'>
<data section='diff'>if (reportService != null)</data>
<data section='diff'>return true;</data>
<data section='diff'>return false;</data>
<data section='changes'
field='file'>ConvertHistoryWages.java</data>
<data section='changes'
field='version'>\main\spr2010_apr_dev\2</data>
<data section='changes'
field='date'>20100310.102844</data>
<data section='changes' field='user'>jryan</data>
<data section='changes' field='cr_number'>602018</data>
<data section='changes' field='comment'>fix for log
5960</data>
<data section='diff'>1296a1297,1298</data>
<data section='diff'></data>
</interface-categories>
<interface-categories name='Source Changes'
category='Source'>
<data section='diff'>if (reportService != null)</data>
<data section='diff'>return true;</data>
<data section='diff'>return false;</data>
<data section='changes'
field='file'>ConvertHistoryWages.java</data>
<data section='changes'
field='version'>\main\spr2010_apr_dev\2</data>
<data section='changes'
field='date'>20100310.102844</data>
<data section='changes' field='cr_number'>602018</data>
<data section='changes' field='comment'>fix for log
5960</data>
<data section='diff'>1296a1297,1298</data>
<data section='diff'></data>
</interface-categories>
</category-source>
<category-source>
<interface-categories name='Source Changes'
category='Source'>
<data section='diff'>if (reportService != null)</data>
<data section='diff'>return true;</data>
<data section='diff'>return false;</data>
<data section='changes'
field='file'>ConvertHistoryWages.java</data>
<data section='changes'
field='date'>20100310.102844</data>
<data section='changes' field='user'>jryan</data>
<data section='changes' field='cr_number'>602018</data>
<data section='diff'>1296a1297,1298</data>
<data section='diff'></data>
</interface-categories>
</category-source>
</server-manifest>
<?xml version='1.0' encoding='utf-8'?> <xsl:stylesheet version='1.0'
xmlns='http://www.w3.org/1999/xhtml'
xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>
<xsl:output omit-xml-declaration='no' method='xml' indent='yes'
xml:space='default' encoding='utf-8'/>
<xsl:template match='/'>
<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en'>
<head>
<title>table example</title>
<style
type='text/css'>table{table-layout:fixed;width:auto}</style>
</head>
<body>
<table width='0' summary='summary goes here for
accessibility'>
<caption>caption goes here for
accessibility</caption>
<thead>
<tr>
<th scope='col'>File</th>
<th scope='col'>Version</th>
<th scope='col'>Date</th>
<th scope='col'>User</th>
<th scope='col'>CR Number</th>
<th scope='col'>Comment</th>
</tr>
</thead>
<tfoot><!-- optional -->
<tr>
<th>File</th>
<th>Version</th>
<th>Date</th>
<th>User</th>
<th>CR Number</th>
<th>Comment</th>
</tr>
</tfoot>
<xsl:apply-templates select='//category-source'/>
</table>
</body>
</html>
</xsl:template>
<xsl:template match='category-source'>
<tbody><xsl:apply-templates
select='./interface-categories'/></tbody>
</xsl:template>
<xsl:template match='interface-categories'>
<tr>
<td scope='row'><xsl:value-of
select="./data[(_at_)field='file']"/> </td>
<td><xsl:value-of
select="./data[(_at_)field='version']"/> </td>
<td><xsl:value-of
select="./data[(_at_)field='date']"/> </td>
<td><xsl:value-of
select="./data[(_at_)field='user']"/> </td>
<td><xsl:value-of
select="./data[(_at_)field='cr_number']"/> </td>
<td><xsl:value-of
select="./data[(_at_)field='comment']"/> </td>
</tr>
</xsl:template>
</xsl:stylesheet>
--~------------------------------------------------------------------
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>
--~--
--~------------------------------------------------------------------
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>
--~--