Hi, I'm trying to get the sum of named columns but
am running into trouble. I'd like to get the total for
columns having a hasTotal attribute. The xsl fragment I'm
trying to use is below. The problem is that the nodelist
param is illegal (select="//$curname"). I can't seem to
create a nodelist without hardcoding the element name
(select="//TradeType"), but I don't know in advance which
elements will be present and which ones have totals.
<xsl:for-each select="TradeEntry[position()=1]/*">
<xsl:variable name="curname" select="name(current())" />
<xsl:if
test="//ColumnInfo/column[@colname=name(current())]/@hasTotal">
<xsl:call-template name="getSum">
<xsl:with-param name="nodelist"
select="//$curname"/>
</xsl:call-template>
</xsl:if>
</xsl:for-each>
<xsl:template name="getSum">
<xsl:param name="nodelist"/>
<xsl:value-of select="sum($nodelist)"/>
</xsl:template>
myData.xml ===========================================
<?xml version="1.0" ?>
<TradeData date='2002-03-18'>
<ColumnInfo>
<column colname="TradeType" align="left"/>
<column colname="TradeId" align="center"/>
<column colname="TradeValue" align="right" hasTotal="true"/>
</ColumnInfo>
<Trades>
<TradeEntry>
<TradeType>TypeA</TradeType>
<TradeId>12345</TradeId>
<TradeValue>100.00</TradeValue>
</TradeEntry>
<TradeEntry>
<TradeType>TypeB</TradeType>
<TradeId>45678</TradeId>
<TradeValue>500.00</TradeValue>
</TradeEntry>
<TradeEntry>
<TradeType>TypeC</TradeType>
<TradeId>56789</TradeId>
<TradeValue>350.00</TradeValue>
</TradeEntry>
</Trades>
</TradeData>
==========================================================
Thanks,
- Steve
- Stephen Friedland
- stephen_r_friedland@xxxxxxxxx
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
|