[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Mods and Looping

Subject: Mods and Looping
From: "gary cor" <stuff4gary@xxxxxxxxxxx>
Date: Mon, 10 Jun 2002 11:23:29 +0000
xsl mod
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

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.