Subject: XSLT: SUM function or "+" operator usage problems to display subtotal/total From: "Albert Tsun" <albert.tsun@xxxxxxxxxxxx> Date: Fri, 27 Oct 2000 17:26:16 +0800 |
Hi all, I had a transform problems which is related to some arithmetic operation and displaying total/subtotal problems. For example I have a XML like this <Report > <Header> <ReportID>01</ReportID> <Title>Trade Report</Title> </Header> <Trade> <Record> <Ref>0001<Ref> <User>User1</User> </Item> <Product>ABC</Product> <Price>100.00</Price> <Item> </Item> <Product>CDE</Product> <Price>200.00</Price> <Item> </Record> <Record> <Ref>0002<Ref> <User>User2</User> </Item> <Product>ABC</Product> <Price>100.00</Price> <Item> </Item> <Product>CDE</Product> <Price>200.00</Price> <Item> </Record> <Trade> </Report> Output: ID : 01 Trade Report Product Price --------------------------------------------------------- Sales : User 1 ABC 100.00 CDE 200.00 ------------------ Subtotal 300.00 Sales : User 2 ABC 100.00 CDE 200.00 ------------------ Subtotal 300.00 ------------------- Total 600.00 my XML: <xsl:variable name="rptid" select="Report/Header/ReportID/text()"> <xsl:variable name="title" select="Report/Header/Title/text()"> <xsl:variable name="subtotal">0</xsl:variable> <xsl:variable name="total">0</xsl:variable> ( ... Is this something wrong here??? ..) <xsl:template match="Report"> <xsl:apply-template select="*[not(self::Header)]"/> </xsl:template> <xsl:template match="Trade"> (.. Print Report Title...) <xsl:apply-templates select="Record"/> (....How to Print each trade total using total variable ????...) (... How to Reset total variable to 0 ???..) </xsl:template> <xsl:template match="Record"> <xsl:for-each select="item"> (.... Print each line ..) (... increment the total, subtotal by value of <Price>) <xsl:variable name="subtotal"> <xsl:value-of select="$subtotal+number(Price)"> </xsl:variable> <xsl:variable name="total"> <xsl:value-of select="$total+number(Price)"> </xsl:variable> (..... however, this does not work, would someone point me to the right way of sum up in for-each loop ??...) (..... if possible, please show me sample code ??...) </xsl:for-each> (.... How to print out subtotal here and reset the subtotal to 0 ???... ) </xsl:template> Thank you very much in advance. Albert Tsun XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: Entity Reference Question, Tony Graham | Thread | Xalan: formatted output, Matthias O. Will |
Re: Rendering an HTML table twice, Jeni Tennison | Date | RE: html to xml, Sebastian Rahtz |
Month |