xsl-list
[Top] [All Lists]

Re: [xsl] Create Table

2010-03-22 14:57:36
HI Eric & List,

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

Thanks.,
Bernie

 


----- Original Message ----
From: Eric J. Bowman <eric(_at_)bisonsystems(_dot_)net>
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Cc: bernie bonn <moochambo(_at_)yahoo(_dot_)com>
Sent: Sat, March 20, 2010 5:06:36 PM
Subject: Re: [xsl] Create Table

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

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