I am populating a table dynamically using xml data.
The elements in the xml may be present or absent. So I
set up all the possible fields in a lookup table
(TableStruct). I need to cater for an element which
may exist in one row but absent in another. So for
each element in the lookup table, if a count of the
row elements reveal that the named element exist in
one or more row, I do a td entry and populate it
accordingly.
I have the following template which works ok for what
I am doing:
<xsl:template match="Rows/Row" mode="celldata">
<xsl:variable name="thisitem" select="."/>
<tr>
<xsl:for-each select="$TableStruct/Row/*">
<xsl:variable name="ItemName"
select="string(name(.))"/>
<xsl:if
test="count($thisitem/..//*[name(.)=$ItemName]) >
0">
<td nowrap="true">
<xsl:value-of
select="$thisitem/*[name()=name(current())]"/>
</td>
</xsl:if>
</xsl:for-each>
</tr>
</xsl:template>
I am now trying to make this template a named template
(so I can reuse with different node-sets) as follows:
<xsl:template name="OptionalFldsTblCellData">
<xsl:param name="row-node" select="/.."/>
<xsl:param name="lookup-node" select="/.."/>
<!--xsl:variable name="thisitem" select="."/-->
<xsl:for-each select="$row-node">
<tr>
<xsl:for-each select="$lookup-node/*">
<xsl:variable name="ItemName"
select="string(name(.))"/>
<!--xsl:if
test="count($thisitem/..//*[name(.)=$ItemName]) >
0"-->
<xsl:if
test="count($row-node/..//*[name(.)=$ItemName]) >
0">
<td nowrap="true">
<xsl:value-of
select="$row-node/*[name()=name(current())]"/>
</td>
</xsl:if>
</xsl:for-each>
</tr>
</xsl:for-each>
</xsl:template>
I call the named template as follows:
<xsl:call-template name="OptionalFldsTblCellData">
<xsl:with-param name="row-node" select="//Row"/>
<xsl:with-param name="lookup-node"
select="$TableStruct/Row"/>
</xsl:call-template>
However my table gets populated with repeated entries
of the first row. So if i have 3 rows in the xml, I
get 3 rows in the table showing the first row's data.
Can you help spot the error?
Thanks
Imrran
__________________________________________________
Do you Yahoo!?
Yahoo! Tax Center - forms, calculators, tips, more
http://taxes.yahoo.com/
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list