Subject: Re: [xsl] sum() with selective attribute From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx> Date: Mon, 06 Jan 2003 17:07:24 -0500 |
for the given xml shown below, I would get a grand total per each currency...
I guess I can do something like sum(/REPORT/ENTITY/FUND_GROUP/ROW/SOME_VALUE) along with "xsl:if", but I'd like to avoid scanning through the tree again looking up CURRENCY attribute... any suggestion?
T:\ftemp>type insoo.xml <REPORT> <ENTITY NUMBER="1"> <FUND_GROUP CURRENCY="GBP"> <ROW> <SOME_VALUE>100</SOME_VALUE> </ROW> <ROW> <SOME_VALUE>200</SOME_VALUE> </ROW> <ROW> <SOME_VALUE>300</SOME_VALUE> </ROW> </FUND_GROUP>
<FUND_GROUP CURRENCY="USD"> <ROW> <SOME_VALUE>100</SOME_VALUE> </ROW> <ROW> <SOME_VALUE>200</SOME_VALUE> </ROW> <ROW> <SOME_VALUE>300</SOME_VALUE> </ROW> </FUND_GROUP> </ENTITY>
<ENTITY NUMBER="2"> <FUND_GROUP CURRENCY="GBP"> <ROW> <SOME_VALUE>100</SOME_VALUE> </ROW> <ROW> <SOME_VALUE>200</SOME_VALUE> </ROW> </FUND_GROUP>
<FUND_GROUP CURRENCY="USD"> <ROW> <SOME_VALUE>200</SOME_VALUE> </ROW> <ROW> <SOME_VALUE>300</SOME_VALUE> </ROW> </FUND_GROUP> </ENTITY>
T:\ftemp>type insoo.xsl <?xml version="1.0" encoding="iso-8859-1"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="/"> <currency-sums> <xsl:for-each select="$currencies"> <xsl:if test="generate-id(.)= generate-id( $currencies[ @CURRENCY = current()/@CURRENCY ] )"> <sum currency="{@CURRENCY}"> <xsl:value-of select="sum( $currencies[@CURRENCY= current()/@CURRENCY]/ROW/SOME_VALUE )"/> </sum> </xsl:if> </xsl:for-each> </currency-sums> </xsl:template>
T:\ftemp>saxon insoo.xml insoo.xsl <?xml version="1.0" encoding="utf-8"?> <currency-sums> <sum currency="GBP">900</sum> <sum currency="USD">1100</sum> </currency-sums> T:\ftemp>
-- Upcoming hands-on in-depth XSLT/XPath and/or XSL-FO: - North America: Feb 3 - Feb 7,2003
G. Ken Holman mailto:gkholman@xxxxxxxxxxxxxxxxxxxx Crane Softwrights Ltd. http://www.CraneSoftwrights.com/s/ Box 266, Kars, Ontario CANADA K0A-2E0 +1(613)489-0999 (F:-0995) ISBN 0-13-065196-6 Definitive XSLT and XPath ISBN 0-13-140374-5 Definitive XSL-FO ISBN 1-894049-08-X Practical Transformation Using XSLT and XPath ISBN 1-894049-10-1 Practical Formatting Using XSL-FO Male Breast Cancer Awareness http://www.CraneSoftwrights.com/s/bc
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] sum() with selective attr, Mike Brown | Thread | [xsl] Parameters in XPath, Juan Carlos Gonzalez |
Re: [xsl] 'Problems getting '&' out, Mike Brown | Date | RE: [xsl] disable-output-escaping=", Andrew Milkowski |
Month |