p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   XSLT (http://p2p.wrox.com/forumdisplay.php?f=86)
-   -   creating table from cards (http://p2p.wrox.com/showthread.php?t=30243)

orrery June 8th, 2005 04:33 PM

creating table from cards
 
I have an XML file that contains a root element and a many "card" elements. For simplicity, we can assume that a card contains a single line of text. I need help with creating an XSLT stylesheet that will sandwich the cards (to be called "cells" when transformed) in groups of 3 within a "row" element, and groups of 3 row elements within a table element. So I want to achieve something like:
<tables>
  <table>
    <row>
       <cell>Sentence 1.</cell>
       <cell>Sentence 2.</cell>
       <cell>Sentence 3.</cell>
    </row>
    <row>
        ...
    </row>
    <row>
        ...
        <cell>Sentence 9.</cell>
    </row>
  </table>
  <table>
        <cell>Sentence 10.</cell>
    ...
  </table>
  ...
</tables>

Suggestions? Thanks for your help.



Chris

mhkay June 9th, 2005 08:31 AM

for-each card[position() mod 9 = 1]
  <table>
    for-each (.|following-sibling[position()<9])[position() mod 3 = 1]
      <tr>
        for-each (.|following-sibling[position()<3])
          <td>
             value-of .


Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference


All times are GMT -4. The time now is 06:24 AM.

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