Stefano Mazzocchi <[EMAIL PROTECTED]> wrote:

> Here is the snipped code I had to write a few days ago in order to 
> generate a table of picture thumbnails. Input is something like this
> 

  <fotografie>
   <foto id="1">whatever</foto>
   <foto id="2">blah</foto>
  </fotografie>

<snip on procedurally oriented XSLT/>

I don't have time to spend on this, but I think what you really want is
something more like

        <xsl:template match="fotografie">
                <table class="fotografie">
                        <xsl:for-each select="*[position() mod $columns =
1]">
                                <xsl:call-template name="rows"/>
                        </xsl:for-each>
                </table>
        </xsl:template>

        <!-- generate rows-->
        <xsl:template name="rows">
                <tr valign="top">
                        <xsl:variable name="lastRowPos" select="position()+
$columns - 1"/>
                        <xsl:apply-templates mode="cols" select=". |
following-sibling::*[position() &lt; $lastRowPos]"/>
                </tr>
        </xsl:template>

        <!-- generate columns -->
        <xsl:template match="*" mode="cols">
                <td align="center" width="{format-number((1 div $columns),
'##%')}">
                        <xsl:template match="foto">
                                <xsl:value-of select="."/>
                        </xsl:template>
                </td>
        </xsl:template>

If you really need the blank cells added in you can do that in the rows
template by calculating if the total # of fotos mod $columns is less than
$columns and just generate the extra <td><br /></td directly to fill out the
table...

Reply via email to