[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Performing an expression on attributes of a node-set
Jim Sproull wrote: > But I need the sum of each (price*qty). I tried everything I could think > of, but no luck. Any clues on how to do this? A solution follows. However, as an alternative, assuming you are in control of the source document, could you include another attribute which is simply @qty * @price. You could then use sum( .. ). Sometimes a bit of redundancy is not a bad thing ! Otherwise : <xsl:variable name="Items" select="//Item"/> <xsl:variable name="TotalValue"> <xsl:call-template name="Total"> <xsl:with-param name="Items" select="$Items"/> <xsl:with-param name="RunningTotal" select="0"/> </xsl:call-template> </xsl:variable> Total = <xsl:value-of select="format-number($TotalValue, '####0.0#')"/> </xsl:template> <xsl:template name="Total"> <xsl:param name="Items"/> <xsl:param name="RunningTotal"/> <xsl:choose> <xsl:when test="not($Items)"> <xsl:copy-of select="$RunningTotal"/> </xsl:when> <xsl:otherwise> <xsl:variable name="CurrentTotal" select="$RunningTotal + ($Items[1]/@qty * $Items[1]/@price)"/> <xsl:call-template name="Total"> <xsl:with-param name="Items" select="$Items[position()>1]"/> <xsl:with-param name="RunningTotal" select="$CurrentTotal"/> </xsl:call-template> </xsl:otherwise> </xsl:choose> </xsl:template> Regards Nick Browne Slipstone Ltd XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|