View Single Post
  #1 (permalink)  
Old November 14th, 2003, 09:49 PM
JPMRaptor JPMRaptor is offline
Registered User
 
Join Date: Nov 2003
Location: , , .
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.

Reply With Quote