<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 <..> 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.
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>