[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Mods and Looping
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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|