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 November 14th, 2003, 09:49 PM
Registered User
 
Join Date: Nov 2003
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default XML List -> HTML table

I'm trying to create a 3 column HTML table from an xml list. The source XML looks something like:
<root>
 <child id="1"/>
 <child id="2"/>
 ...
</root>

I have a template setup to output the needed info for each child but can't figure out how to generate the proper "tr" tags to break things into rows.

So far my best try looks like:
 <xsl:template match="root">
    <html><body><table>
      <xsl:for-each select="child">

       <xsl:if test="0 = ((position()-1) mod 2)">
        <tr>
         <xsl:apply-templates select="." />
         <xsl:apply-templates select="following-sibling::child" />
        </tr>
       </xsl:if>
      </xsl:for-each>
    </table></body></html>
 </xsl:template>

What I end up with from this is for each node matching the mod test it runs my child template for all nodes after that. The following-sibling call is the one causing the multiple calls to the child template.

I'm using the jdk 1.4.2_02 bundled XSLT engine.

 
Old November 14th, 2003, 10:19 PM
Registered User
 
Join Date: Nov 2003
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Never mind, found the solution in the archives:
http://p2p.wrox.com/archive/xslt/2001-05/116.asp






Similar Threads
Thread Thread Starter Forum Replies Last Post
transform a xml to a html table robert_trudel_fr XSLT 3 December 3rd, 2006 02:16 PM
How to insert <br> in a table with this xml/xsl? andigra XSLT 1 September 22nd, 2006 07:01 AM
Achitecture ? SQL -> XML -> ASP -> PDF or HTML Frm jstrong Classic ASP XML 0 July 9th, 2005 01:18 PM
XML to HTML Table with Sorting and Distinct VictorMk XSLT 4 April 23rd, 2004 06:29 PM
putting xml data in a html <table> rev XSLT 4 September 10th, 2003 08:49 AM





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