Breaking up is hard to do.

Subject: Breaking up is hard to do.
From: Joel Hughes <joel@xxxxxxxxxxx>
Date: Sat, 19 Feb 2000 23:46:34 -0500
Attempting to break elements at context node into groups of three for tabular output.
(my real code is appended).
 
Given a node set: <field>1</field><field>2</field><field>3</field><field>4</field><field>5</field>...<field>n</field> ...
We desire output:
<tr>
    <td>1</td>
    <td>2</td>
    <td>3</td>
</tr>
<tr>
    <td>4</td>
    <td>5</td>
        ...
    <td>n</td>
</tr>
 
Two approaches
1. Increment a counter during a for-each loop.  At break point, output </tr><tr>
    I am unable to generate a </tr><tr> in my output.
    <xsl:text> produces &lt;..&gt; as expected
    and an explicit </tr><tr> causes parsing issues as now the xsl document is not well formed.
 
2. Recursion using call-template.  
    Because call-template does not change the current node list I am unable to move or traverse the node list.
    Each call to 'colCounter' generates three input fields, but only one has data output as there is only one element in the node list inside the called template.
 
I've reviewed http://www.hcrc.ed.ac.uk/~dmck/xslt-tutorial.html and this was the basis for my recursion approach.
This one has me really stuck.
Thanks for your time.
 
Attached Code.
1. increment
 
 <xsl:template match="aime-mod-genre">
   <xsl:param name="maxCol" select="3"/>
 
   <tr>
 
   <xsl:for-each select="field">
 
     <xsl:element name="td">
       <xsl:attribute name="class"></xsl:attribute>
       <xsl:element name="input">
         <xsl:attribute name="type">checkbox</xsl:attribute>
         <xsl:variable name="genreid"><xsl:value-of select="genreid"/></xsl:variable>
         <xsl:attribute name="value"><xsl:value-of select="genreid"/></xsl:attribute>
         <xsl:attribute name="name"><xsl:value-of select="genretitle"/></xsl:attribute>
         <xsl:attribute name="title"><xsl:value-of select="description"/></xsl:attribute>
           <!-- determine if pre-check -->
         <xsl:if test="boolean(/page/aime/aime-form/aime-mod-user/field[modid=$genreid])">
           <xsl:attribute name="checked">true</xsl:attribute>
         </xsl:if>
       </xsl:element> <!-- end input -->
       <!-- label for check box -->
       <xsl:value-of select="genretitle"/>
     </xsl:element> <!-- end td -->
 
       <!-- test for row end/start -->
     <xsl:if test="((position() mod $maxCol) = 0)">
       </tr>
       <tr>
     </xsl:if>
   </xsl:for-each> <!-- end field -->
 
   </tr>
 
 </xsl:template> <!-- end aime-genre-->
 
2. recursion
    <!-- process all field elements -->
    <!-- call colCounter to place 3 per row -->
    <!-- Note: it is this main functions responsibility -->
    <!-- to increment the index counter by maxCol -->
    <!-- on each loop -->
  <xsl:template match="aime-mod-genre">
      <!-- maxCol is 2, as indexing is zero based -->
    <xsl:param name="maxCol" select="2"/>
    <xsl:param name="index" select="0 - $maxCol"/>
 
      <!-- for each element - in this case "field" -->
      <!-- we call colCounter -->
      <!-- hopefully it will consume three fields -->
    <xsl:for-each select="field">
      <xsl:element name="tr">
        <xsl:call-template name="colCounter">
          <xsl:with-param name="maxCol" select="$maxCol"/>
          <xsl:with-param name="curCol" select="0"/>
          <xsl:with-param name="index" select="$index + $maxCol"/>
        </xsl:call-template> <!-- end call-template -->
      </xsl:element> <!-- end tr -->
    </xsl:for-each> <!-- end field -->
  </xsl:template> <!-- end aime-genre-->
 
    <!-- Recursive function will create -->
    <!-- maxCol columns per table row -->
  <xsl:template name="colCounter" match="field">
    <xsl:param name="maxCol"/>
    <xsl:param name="curCol"/>
    <xsl:param name="index"/>
 
      <!-- Base case test -->
      <!-- if maxCol equals curCol then end recusion -->
    <xsl:if test="$maxCol >= $curCol">
      <xsl:element name="td">
        <xsl:attribute name="class"></xsl:attribute>
        <xsl:element name="input">
          <xsl:attribute name="type">checkbox</xsl:attribute>
          <xsl:variable name="genreid"><xsl:value-of select="self::field[$index]/genreid"/></xsl:variable>
          <xsl:attribute name="value"><xsl:value-of select="self::field[$index]/genreid"/></xsl:attribute>
          <xsl:attribute name="name"><xsl:value-of select="self::field[$index]/genretitle"/></xsl:attribute>
          <xsl:attribute name="title"><xsl:value-of select="self::field[$index]/description"/></xsl:attribute>
          <xsl:attribute name="alt"><xsl:value-of select="self::field[$index]/description"/></xsl:attribute>
            <!-- determine if pre-check -->
          <xsl:if test="boolean(/page/aime/aime-form/aime-mod-user/field[modid=$genreid])">
            <xsl:attribute name="checked">true</xsl:attribute>
          </xsl:if>
        </xsl:element> <!-- end input -->
        <!-- label for check box -->
        <xsl:value-of select="self::field[$index]/genretitle"/>
      </xsl:element> <!-- end td -->
 
        <!-- Recursive call for next columen element -->
      <xsl:call-template name="colCounter">
        <xsl:with-param name="maxCol" select="$maxCol"/>
        <xsl:with-param name="curCol" select="$curCol + 1"/>
        <xsl:with-param name="index" select="$index + 1"/>
      </xsl:call-template>
 
    </xsl:if>
  </xsl:template>
_________________________________
Joël Hughes
REDKNEE.com
      Intelligent Mobile Internet Services
 
phone/pager/v-mail: 905-625-8235
e-mail (business): joel@xxxxxxxxxxx
e-mail (personal): joel_hughes@xxxxxxx
url: www.redknee.com
 
 
Current Thread