RE: [xsl] generate a table with rows and exactly four columns with xsl

Subject: RE: [xsl] generate a table with rows and exactly four columns with xsl
From: "Passin, Tom" <tpassin@xxxxxxxxxxxx>
Date: Wed, 24 Sep 2003 17:34:15 -0400
[ Markus Hanel]
> I am a beginner with xml, and my problem is to create a table 
> with rows
> and exactly 4 columns to number automatic a few forms. The last row
> should be filled up to 4 columns with empty cells if necessary.
> many thanks!
> markus

1) Do you want to produce an __html__ table?  
2) If so, do you want the data slots to be laid out as follows?

test1 test2 test3 test4
test5 test6 test7 test8
testn-1 testn [blank] [blank]

3) Does the dtd add anything that could affect the structure?

4) If an html table, do you really need any blank cells at the end of
the last row (a table will display perfectly well without them).

If 1) and 2) but not 3), then you basically need to use the  mod
operator to discover when to insert a new row.  Just remember that you
want to insert entire elements, not just a start tag here and a stop tag
there. If you really do need those blank cells at the end - I mean, you
need some content in them -  you will have to do a test to see if the
data runs out before a row is filled up, and to add them.  But probably
you do not need them.

Here is a sketch of one simple way to get what you may want - I leave it
to you to turn it into html or whatever you want -

<xsl:template match="/interview">
   <xsl:apply-templates select='form[(position() -1) mod 4 = 0]'

<xsl:template match='form' mode='row'>
   <cell><xsl:value-of select='.'/></cell>
   <cell><xsl:value-of select='following-sibling::form[1]'/></cell>
   <cell><xsl:value-of select='following-sibling::form[2]'/></cell>
   <cell><xsl:value-of select='following-sibling::form[3]'/></cell>


Tom P

> <?xml version="1.0" encoding="ISO-8859-1" standalone="no"?>
> <?xml-stylesheet href="tabelle.xsl" type="text/xsl"?>
> <!DOCTYPE interview SYSTEM "tabelle.dtd">
> <interview>
> <form>test1</form>
> <form>test2</form>
> <form>test3</form>
> <form>test4</form>
> <form>test5</form>
> <form>test6</form>
> <form>test7</form>
> <form>test8</form>
> <form>test9</form>
> <form>test10</form>
> <form>test11</form>
> <form>test12</form>
> <form>test13</form>
> </interview>

 XSL-List info and archive:

Current Thread