blackfrancis75
asked on
XSLT: modifying a variable
Hello,
I have a little template which is meant to iterate over all the /records of my XML document and add ./field[7] to a running total.
I know what you're going to say - use sum() instead, but the problem is I need the summing to be conditional (so later on I'll put <xsl:if> processing
in this template).
Anyway, is it possible to do something like the following;
<xsl:template name="calc_vat">
<xsl:variable name="bab" select="0"/>
<xsl:for-each select="/tabledata/record" ><xsl:vari able name="bab" select="number($bab)+${./f ield[7]}"/ ></xsl:for -each>
<xsl:value-of select="$bab"/></xsl:templ ate>
it isn't working at the moment which I presume is because the variable "bab" is being redeclared within my <for-each> processing loop,
but what I really want to do is add the field[7] value to the "bab" figure on each iteration.
Can someone give me some pointers or an alternative solution?
Thanks
I have a little template which is meant to iterate over all the /records of my XML document and add ./field[7] to a running total.
I know what you're going to say - use sum() instead, but the problem is I need the summing to be conditional (so later on I'll put <xsl:if> processing
in this template).
Anyway, is it possible to do something like the following;
<xsl:template name="calc_vat">
<xsl:variable name="bab" select="0"/>
<xsl:for-each select="/tabledata/record"
<xsl:value-of select="$bab"/></xsl:templ
it isn't working at the moment which I presume is because the variable "bab" is being redeclared within my <for-each> processing loop,
but what I really want to do is add the field[7] value to the "bab" figure on each iteration.
Can someone give me some pointers or an alternative solution?
Thanks
ASKER
ah, forgive me for being slow but could you provide a short example?
that'd really help. ta
that'd really help. ta
ASKER
Im guessing you mean something like this:
<xsl:template match="/tabledata/record" name="total">
<xsl:for-each select="/tabledata/record" >
<xsl:if test="./@include">
<xsl:value-of select="format-number(sum( ./field[7] ),'#0.00') "/>
</xsl:if>
</xsl:for-each>
</xsl:template>
But im not sure how to make this template return ONLY the sum of all the filtered nodes, if you could help out that'd be great.
<xsl:template match="/tabledata/record" name="total">
<xsl:for-each select="/tabledata/record"
<xsl:if test="./@include">
<xsl:value-of select="format-number(sum(
</xsl:if>
</xsl:for-each>
</xsl:template>
But im not sure how to make this template return ONLY the sum of all the filtered nodes, if you could help out that'd be great.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
:)
Don