[xsl] Mods and Looping

Subject: [xsl] Mods and Looping
From: "gary cor" <stuff4gary@xxxxxxxxxxx>
Date: Mon, 10 Jun 2002 11:23:29 +0000
Dear all,

I have been writing a template which allows me to process columns of content blocks in HTML across the page at different modulus. It works fine but I would very much like to use a loop to optimise the code and apply a blocks at any modulus, can anyone give me any pointers on how I go about doing this? The template that I think needs a loop is the following code (I also wonder at what point it would be more efficient to write a loop, how many mod!)...


<xsl:template name="mod">
<xsl:param name="padding">3</xsl:param>
<xsl:param name="number">1</xsl:param>
<xsl:param name="node" select="image"/>
<xsl:choose>
<xsl:when test="$number='2'">
<table xsl:use-attribute-sets="table.0">
<tr>
<td valign="top">
<xsl:apply-templates select="$node[position() mod $number = 1]"/>
</td>
<td>
<xsl:call-template name="spacer">
<xsl:with-param name="width">
<xsl:value-of select="$padding + 2"/>
</xsl:with-param>
</xsl:call-template>
</td>
<td valign="top">
<xsl:apply-templates select="$node[position() mod $number = 0]"/>
</td>
</tr>
</table>
</xsl:when>
<xsl:when test="$number='3'">
<table xsl:use-attribute-sets="table.0">
<tr>
<td valign="top">
<xsl:apply-templates select="$node[position() mod $number = 1]"/>
</td>
<td>
<xsl:call-template name="spacer">
<xsl:with-param name="width">
<xsl:value-of select="$padding + 2"/>
</xsl:with-param>
</xsl:call-template>
</td>
<td valign="top">
<xsl:apply-templates select="$node[position() mod $number = 2]"/>
</td>
<td>
<xsl:call-template name="spacer">
<xsl:with-param name="width">
<xsl:value-of select="$padding + 2"/>
</xsl:with-param>
</xsl:call-template>
</td>
<td valign="top">
<xsl:apply-templates select="$node[position() mod $number = 0]"/>
</td>
</tr>
</table>
</xsl:when>
<xsl:when test="$number='4'">
<table xsl:use-attribute-sets="table.0">
<tr>
<td valign="top">
<xsl:apply-templates select="$node[position() mod $number = 1]"/>
</td>
<td>
<xsl:call-template name="spacer">
<xsl:with-param name="width">
<xsl:value-of select="$padding + 2"/>
</xsl:with-param>
</xsl:call-template>
</td>
<td valign="top">
<xsl:apply-templates select="$node[position() mod $number = 2]"/>
</td>
<td>
<xsl:call-template name="spacer">
<xsl:with-param name="width">
<xsl:value-of select="$padding + 2"/>
</xsl:with-param>
</xsl:call-template>
</td>
<td valign="top">
<xsl:apply-templates select="$node[position() mod $number = 3]"/>
</td>
<td>
<xsl:call-template name="spacer">
<xsl:with-param name="width">
<xsl:value-of select="$padding + 2"/>
</xsl:with-param>
</xsl:call-template>
</td>
<td valign="top">
<xsl:apply-templates select="$node[position() mod $number = 0]"/>
</td>
</tr>
</table>
</xsl:when>
<xsl:when test="$number='5'">
<table xsl:use-attribute-sets="table.0">
<tr>
<td valign="top">
<xsl:apply-templates select="$node[position() mod $number = 1]"/>
</td>
<td>
<xsl:call-template name="spacer">
<xsl:with-param name="width">
<xsl:value-of select="$padding + 2"/>
</xsl:with-param>
</xsl:call-template>
</td>
<td valign="top">
<xsl:apply-templates select="$node[position() mod $number = 2]"/>
</td>
<td>
<xsl:call-template name="spacer">
<xsl:with-param name="width">
<xsl:value-of select="$padding + 2"/>
</xsl:with-param>
</xsl:call-template>
</td>
<td valign="top">
<xsl:apply-templates select="$node[position() mod $number = 3]"/>
</td>
<td>
<xsl:call-template name="spacer">
<xsl:with-param name="width">
<xsl:value-of select="$padding + 2"/>
</xsl:with-param>
</xsl:call-template>
</td>
<td valign="top">
<xsl:apply-templates select="$node[position() mod $number = 4]"/>
</td>
<td>
<xsl:call-template name="spacer">
<xsl:with-param name="width">
<xsl:value-of select="$padding + 2"/>
</xsl:with-param>
</xsl:call-template>
</td>
<td valign="top">
<xsl:apply-templates select="$node[position() mod $number = 0]"/>
</td>
</tr>
</table>
</xsl:when>
<xsl:otherwise>
<table xsl:use-attribute-sets="table.0">
<tr>
<td valign="top">
<xsl:apply-templates select="$node[position() mod 1 = 0]"/>
</td>
</tr>
</table>
</xsl:otherwise>
</xsl:choose>
</xsl:template>


Many thanks for any help in advance

G.



_________________________________________________________________
Chat with friends online, try MSN Messenger: http://messenger.msn.com


XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list



Current Thread