[xsl] Re: dynamic html table generation

Subject: [xsl] Re: dynamic html table generation
From: "Dimitre Novatchev" <dnovatchev@xxxxxxxxx>
Date: Sun, 26 Oct 2003 08:41:36 +0100
> I have the following problem. I do have some elements (not knowing their
> count) and want to insert them into table-columns where always after 4
> inserted elements the next 4 elements should be stored in the next column.
> have alreaday done this with always beginning a new _row_ every 4


> But how can that be done with columns?

This transformation:

<xsl:stylesheet version="1.0"
  <xsl:template match="/">
          <xsl:call-template name="makeNRowsTable">
            <xsl:with-param name="pcolSize" select="4"/>
            <xsl:with-param name="ptheNodes" select="/*/*"/>

  <xsl:template name="makeNRowsTable">
    <xsl:param name="pcolSize" select="1"/>
    <xsl:param name="ptheNodes" select="/.."/>

    <xsl:for-each select="$ptheNodes[position() &lt;= $pcolSize]">
     <xsl:variable name="vthisMod" select="position() mod $pcolSize"/>
            select="$ptheNodes[position() mod $pcolSize = $vthisMod]">
          <td><xsl:value-of select="."/></td>

when applied on this source.xml:


produces the wanted result:


Note that the "makeNRowsTable" template accepts an arbitrary node-set, whose
elements may or may not be siblings. This is an improvement over the
"traditional" algorithm, which assumes that all nodes in the node-set are


Dimitre Novatchev.
http://fxsl.sourceforge.net/ -- the home of FXSL

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

Current Thread