cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Hunsberger, Peter" <>
Subject RE: [RT] the quest for the perfect template language
Date Thu, 03 Apr 2003 23:35:31 GMT
Stefano Mazzocchi <> 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

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

<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 =
				<xsl:call-template name="rows"/>

	<!-- 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]"/>

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

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

View raw message