Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 22nd, 2006, 05:48 PM
Friend of Wrox
 
Join Date: Jul 2006
Posts: 430
Thanks: 28
Thanked 5 Times in 5 Posts
Send a message via Yahoo to bonekrusher
Default Dynamic HTML table

Hi All,

I am having trouble parsing an XML table into an HTML Table. Here is my XML code:

Code:
                    <table border="7" width="100%">
                        <tbody>
                            <tr>
                                <td width="171">Test</td>
                                <td>TEST</td>
                                <td>TEST a agian</td>
                            </tr>
                            <tr>
                                <td width="171">ok this is good</td>
                                <td>more</td>
                                <td/>
                            </tr>
                            <tr>
                                <td width="171"/>
                                <td/>
                                <td/>
                            </tr>
                        </tbody>
                    </table>


and here is the XSLT template:

Code:
<xsl:template match="JBU:table">
            <html>
                <head>
                    <title/>
                </head>
                <body>
                    <table border="@border">
                        <tbody>
                            <tr>
                                <td>
                                    <xsl:apply-templates/>
                                </td>
                            </tr>
                        </tbody>
                    </table>
                </body>
            </html>
    </xsl:template>


The xml table is dynamic as well as the atributes (width, border etc..)
The code puts all the data in one cell. Based on the XML I posted it should produce 3 rows and 3 columns.

Thanks for the help.
Bones

 
Old September 23rd, 2006, 12:40 PM
Friend of Wrox
 
Join Date: Jul 2006
Posts: 430
Thanks: 28
Thanked 5 Times in 5 Posts
Send a message via Yahoo to bonekrusher
Default

Ok, I was able to do it, but how do I make the attributes of the JBU:table values for the table.

For example: border style, BGcolor etc..

Here is my XSLT
Code:
    <xsl:template match="JBU:table">
        <xsl:for-each select="JBU:tbody">
            <table border="?????????">
                <xsl:for-each select="JBU:tr">
                    <tr bgcolor="??????">
                        <xsl:for-each select="JBU:td">
                            <td>
                                <xsl:value-of select="."/>
                            </td>
                        </xsl:for-each>
                    </tr>
                </xsl:for-each>
            </table>
        </xsl:for-each>
    </xsl:template>


here are my attributes for JBU:table:

            <xs:attribute name="align" type="xs:string"/>
            <xs:attribute name="border"/>
            <xs:attribute name="cellpadding"/>
            <xs:attribute name="bgcolor"/>
            <xs:attribute name="width"/>
            <xs:attribute name="cellspacing"/>
            <xs:attribute name="frame"/>
            <xs:attribute name="rules"/>

 
Old September 23rd, 2006, 12:55 PM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Why is the xsl:for-each select="JBU:tbody" outside the table border="?????????", do you want one table per JBU:tbody? Just move it up one level, or remove it, and insert the border using an attribute value template:
Code:
<xsl:template match="JBU:table">
  <table border="{@border}">
--

Joe (Microsoft MVP - XML)
 
Old September 23rd, 2006, 01:27 PM
Friend of Wrox
 
Join Date: Jul 2006
Posts: 430
Thanks: 28
Thanked 5 Times in 5 Posts
Send a message via Yahoo to bonekrusher
Default

Joe,

Once again thank you for the help. Moving the JBU:tbody up one level did the trick. I cant thank you enough.

Thanks

Bones







Similar Threads
Thread Thread Starter Forum Replies Last Post
help writing dynamic form data to dynamic table ublend SQL Server ASP 1 June 1st, 2007 08:09 AM
help writing dynamic form data to dynamic table ublend Classic ASP Professional 1 June 1st, 2007 08:08 AM
Get html code of dynamic webpages Singalong Pro PHP 0 August 21st, 2006 10:11 PM
Re: Dynamic html tables with xsl? purple XSLT 0 November 2nd, 2005 12:01 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.