This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: loop in creation of table


In my eyes there is a better way to reach the same:

<xsl:template match="parent-of-subsystem_id">
 <table border="1">
  <tr><xsl:apply-templates select="subsystem_id[position() mod 4 =
1]"/></tr>
  <tr><xsl:apply-templates select="subsystem_id[position() mod 4 =
2]"/></tr>
  <tr><xsl:apply-templates select="subsystem_id[position() mod 4 =
3]"/></tr>
  <tr><xsl:apply-templates select="subsystem_id[position() mod 4 =
0]"/></tr>
 </table>
</xsl:template>

<xsl:template match="subsystem_id">
 <td><xsl:value-of select="."/></td>
 <xsl:if test="position()=last()">
  <td colspan="{16 - position()}">&#160;</td>
 </xsl:if>
</xsl:template>
</xsl:stylesheet>

I like to avoid <call-template>s ;-)

Joerg

----- Original Message -----
From: Zwetselaar M. van (Marco)
To: 'xsl-list@lists.mulberrytech.com'
Sent: Wednesday, September 26, 2001 4:11 PM
Subject: RE: [xsl] loop in creation of table

Praveen,

> elements like this- <subsystem_id> value1</subsystem_id>.
> now i have to design a table like the one shown BELOW..  we
> have total of 16 columns and 4 rows.

You could do this at follows, but there will surely be more elegant
solutions:

<xsl:template match="/">
<xsl:call-template name="make-row">
<xsl:with-param name="elements"
select="//subsystem_id[position() mod 4 = 1]" />
</xsl:call-template>
<xsl:call-template name="make-row">
<xsl:with-param name="elements"
select="//subsystem_id[position() mod 4 = 2]" />
</xsl:call-template>
<xsl:call-template name="make-row">
<xsl:with-param name="elements"
select="//subsystem_id[position() mod 4 = 3]" />
</xsl:call-template>
<xsl:call-template name="make-row">
<xsl:with-param name="elements"
select="//subsystem_id[position() mod 4 = 0]" />
</xsl:call-template>
</xsl:template>

<xsl:template name="make-row">
<xsl:param name="elements" />
<tr>
<xsl:for-each select="$elements">
<td><xsl:value-of select="." /></td>
</xsl:for-each>
<td colspan="{16-count($elements)}" />
</tr>
</xsl:template>

Regards,
Marco


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]