xsl-list
[Top] [All Lists]

RE: how to add a </tr> on every position() mod 4 = 0 ?

2002-11-11 02:11:44
Hi,

I have a list in xml, and want to show them in a 4-column 
table (in at least
2 rows). so I would like to add a closing </tr> tag to every <xsl:if
test="position() mod 4 = 0"> but I cannot write a simple 
closing </tr> tag
here, because parser says it's an error. (However a <tr/> 
works for output,
but it's not the clean and sytanctically the best way)

Remember, you're not writing tags with XSLT, but rather building a tree (see 
<http://www.w3.org/TR/xpath#data-model>). Try something in the lines of 

<xsl:template match="foo">
  <table>
    <xsl:for-each select="bar[position() mod 4 = 1]">
      <tr>
        <xsl:apply-templates select=". | following-sibling::bar[position() &lt; 
4]" />
      </tr>
    </xsl:for-each>
  </table>
</xsl:template>

Cheers,

Jarno - Wumpscut: Wreath of Barbs (Album mix)

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