p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   XSLT (http://p2p.wrox.com/forumdisplay.php?f=86)
-   -   XML List -> HTML table (http://p2p.wrox.com/showthread.php?t=6188)

JPMRaptor November 14th, 2003 09:49 PM

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.


JPMRaptor November 14th, 2003 10:19 PM

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



All times are GMT -4. The time now is 05:45 PM.

Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.