cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Joerg Heinicke <joerg.heini...@gmx.de>
Subject Re: [RT] the quest for the perfect template language
Date Thu, 01 May 2003 12:07:05 GMT
What about this one? Not much shorter because of the emptyCellIterator, 
but at least understanding the processing is easier, isn't it?

Regards,

Joerg

<xsl:template match="fotografie">
  <table class="fotografie" border="1">
   <xsl:apply-templates select="foto[position() mod $columns = 1]" 
mode="tr"/>
  </table>
</xsl:template>

<xsl:template match="foto" mode="tr">
  <tr valign="top">
   <xsl:apply-templates select=". | following-sibling::foto[position() 
&lt; $columns]"/>
   <!-- maybe you need to fill up the tr with missing cells -->
   <xsl:if test="not(following-sibling::foto[$columns - 1])">
    <xsl:call-template name="emptyCellIterator">
     <xsl:with-param name="countEmptyCells" select="$columns - count(. | 
following-sibling::foto[position() &lt; $columns])"/>
    </xsl:call-template>
   </xsl:if>
  </tr>
</xsl:template>

<xsl:template match="foto">
  <td align="center" width="{format-number((1 div $columns), '##%')}">
   <xsl:apply-templates/>
  </td>
</xsl:template>

<xsl:template name="emptyCellIterator">
  <xsl:param name="countEmptyCells" select="0"/>
  <xsl:if test="$countEmptyCells > 0">
   <td><br/></td>
   <xsl:call-template name="emptyCellIterator">
    <xsl:with-param name="countEmptyCells" select="$countEmptyCells - 1"/>
   </xsl:call-template>
  </xsl:if>
</xsl:template>



Stefano Mazzocchi wrote:
> Steven Noels wrote:
> 
>> On 3/04/2003 8:52 Jeff Turner wrote:
>>
>>> Pity about losing the declarative processing model.
>>
>>
>>
>> Cannot agree more. Declarative is great SoC.
> 
> 
> Get real: what is declarative in
> 
>  <xsl:choose>
>   <xsl:when test="...">
>    <xsl:call-template name="blah">
>     <xsl:with-param name="whatever>
>      <xsl:for-each select="node()">
>       <xsl:value-of select="."/>
>      </xsl:for-each>
>     </xsl:with-param>
>    </xsl:call-template>
>   </xsl:when>
>   <xsl:otherwise>
>    ...
>   </xsl:otherwise>
>  </xsl:choose>
> 
> ?
> 
> 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>
>  ...
> 
> 
> The stylesheet looks like this:
> 
>   ...
> 
>   <xsl:template match="fotografie">
>    <table class="fotografie">
>     <xsl:call-template name="rowIterator">
>      <xsl:with-param name="row" select="0"/>
>      <xsl:with-param name="rows" select="ceiling(count(//foto) div 
> $columns)"/>
>     </xsl:call-template>
>    </table>
>   </xsl:template>
> 
>   <!-- iterates over rows -->
>   <xsl:template name="rowIterator">
>    <xsl:param name="row"/>
>    <xsl:param name="rows"/>
>    <xsl:if test="$row &lt; $rows">
>     <tr valign="top">
>      <xsl:call-template name="columnIterator">
>       <xsl:with-param name="row" select="$row"/>
>       <xsl:with-param name="column" select="0"/>
>      </xsl:call-template>
>     </tr>
>     <xsl:call-template name="rowIterator">
>      <xsl:with-param name="rows" select="$rows"/>
>      <xsl:with-param name="row" select="$row + 1"/>
>     </xsl:call-template>
>    </xsl:if>
>   </xsl:template>
> 
>   <!-- iterates over columns -->
>   <xsl:template name="columnIterator">
>    <xsl:param name="row"/>
>    <xsl:param name="column"/>
>    <xsl:variable name="item" select="($row * $columns) + $column + 1"/>
>    <xsl:if test="$column &lt; $columns">
>     <td align="center" width="{format-number((1 div $columns), '##%')}">
>      <xsl:choose>
>       <xsl:when test="//foto[$item]">
>        <xsl:apply-templates select="//foto[$item]"/>
>       </xsl:when>
>       <xsl:otherwise>
>        <br/>
>       </xsl:otherwise>
>      </xsl:choose>
>     </td>
>     <xsl:call-template name="columnIterator">
>      <xsl:with-param name="row" select="$row"/>
>      <xsl:with-param name="column" select="$column + 1"/>
>     </xsl:call-template>
>    </xsl:if>
>   </xsl:template>
> 
> 


Mime
View raw message