This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Using sum to Produce a total from combined documents
- From: "Eric Vitiello Jr." <xsl-list at perceive dot net>
- To: xsl-list <xsl-list at lists dot mulberrytech dot com>
- Date: Tue, 2 Jul 2002 14:16:05 -0400
- Subject: [xsl] Using sum to Produce a total from combined documents
- Reply-to: xsl-list at lists dot mulberrytech dot com
I need to get a total using a calculation.
I have two files, one containing current stock information, and the second
contains short stock information, and the number of shares owned.
I need to take the last-sale-price, multiply it by the @shares (in config)
and produce a total. I have this completed, and it wasn't a problem.
I need to create a total for this column though - it should produce a total
value of the portfolio. (adding up all of the values discussed in the
last paragraph.) This would be inserted where the phrase "TOTAL HERE" is below.
I'd greatly appreciate a solution for this. I'm quite sure the solution is simple,
but it's eluding me.
XML and XSLT files are below.
--
Eric Vitiello [Perceive Designs]
<http://www.perceive.net>
Got Geek? <http://www.cafepress.com/got_geek>
(I've removed some data for ease of reading and explanation)
stock.xml
-------------------------------
<nasdaqamex-dot-com>
<equity-quote symbol="DIS">
<issue-name>DISNEY CO WALT HLDG CO</issue-name>
<last-sale-price>18.27</last-sale-price>
</equity-quote>
<equity-quote symbol="SYQTQ">
<issue-name>Syquest</issue-name>
<last-sale-price>.02</last-sale-price>
</equity-quote>
</nasdaqamex-dot-com>
-------------------------------
config.xml
-------------------------------
<config>
<stocks>
<stock symbol="DIS" type="stock" shares="40"/>
<stock symbol="SYQTQ" type="stock" shares="200"/>
</stocks>
</config>
-------------------------------
my XSL, which is being applied to stock.xml:
-------------------------------
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="html" indent="yes" />
<xsl:variable name="config" select="document('config.xml')/config" />
<xsl:template match="nasdaqamex-dot-com">
<div id="stocks">
<table cellspacing="0" cellpadding="1" width="100%">
<tr>
<th>name</th>
<th>symbol</th>
<th>last</th>
<th>value</th>
</tr>
<xsl:apply-templates select="index-quote" />
<xsl:apply-templates select="equity-quote" />
<tr><td align="right" colspan="7">Total Value</td><td>TOTAL HERE</td></tr>
</table>
</div>
</xsl:template>
<xsl:template match="equity-quote">
<tr>
<xsl:attribute name="class">
<xsl:choose>
<xsl:when test="number(net-change-price) < 0">priceDown</xsl:when>
<xsl:otherwise>priceUp</xsl:otherwise>
</xsl:choose>
</xsl:attribute>
<xsl:variable name="currentSymbol" select="@symbol"/>
<td><xsl:value-of select="issue-name"/></td>
<td><xsl:value-of select="@symbol" /></td>
<td><xsl:value-of select="last-sale-price"/></td>
<td><xsl:value-of select="format-number(($config/stocks/stock[@symbol=$currentSymbol]/@shares * last-sale-price),'$###,##0.00;($###,##0.00)')"/></td>
</tr>
</xsl:template>
</xsl:stylesheet>
-------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list