I am a complete newbie in the XSL transformation world and I need your help.
Say I have this XML file:
<?xml version="1.0" encoding="UTF-8"?>
<NAV>
<Funds Description="Funds" Date="2008-01-17">
<Fund Description="Fund 1">
<SubFund Description="Sub Fund 1.1">
<ValuationDate>2008-01-17</Valuation
Date>
<ClosingCapital>1000</ClosingCapital
>
<XRate>1</XRate>
</SubFund>
<SubFund Description="Sub Fund 1.2">
<ValuationDate>2008-01-17</Valuation
Date>
<ClosingCapital>1000</ClosingCapital
>
<XRate>1</XRate>
</SubFund>
<SubFund Description="Sub Fund 1.3">
<ValuationDate>2008-01-17</Valuation
Date>
<ClosingCapital>1000</ClosingCapital
>
<XRate>1</XRate>
</SubFund>
</Fund>
<Fund Description="Fund 2" >
<SubFund Description="Sub Fund 2.1">
<ValuationDate>2008-01-17</Valuation
Date>
<ClosingCapital>4000</ClosingCapital
>
<XRate>2</XRate>
</SubFund>
</Fund>
<Fund Description="Fund 3" >
<SubFund Description="Sub Fund 3.1">
<ValuationDate>2008-01-17</Valuation
Date>
<ClosingCapital>9000</ClosingCapital
>
<XRate>3</XRate>
</SubFund>
<SubFund Description="Sub Fund 3.2">
<ValuationDate>2008-01-17</Valuation
Date>
<ClosingCapital>9000</ClosingCapital
>
<XRate>3</XRate>
</SubFund>
</Fund>
</Funds>
</NAV>
And also this XSL file:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet
version="1.0"
xmlns:xsl="
http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-c
om:xslt"
exclude-result-prefixes="msxsl"
>
<xsl:template match="/">
<html>
<body>
<h2>
<xsl:value-of select="NAV/Funds/@Description" />
</h2>
<xsl:value-of select="NAV/Funds/@Date" />
<br />
<br />
<br />
<table border="1">
<xsl:for-each select="NAV/Funds/Fund">
<tr>
<td>
<xsl:value-of select="@Description"/>
</td>
</tr>
<tr>
<td>Fund Name</td>
<td>Valuation Date</td>
<td>Closing Capital</td>
<td>Closing Capital (Converted)</td>
<td>% of Grand Total</td>
</tr>
<xsl:variable name="FundTotal" select="SubFund/ClosingCapital"></xs
l:variable
>
<xsl:variable name="FundTotalConverted" select="$FundTotal"></xsl:variable>
<xsl:variable name="XRate" select="@XRate"></xsl:variable>
<xsl:for-each select="SubFund">
<xsl:variable name="Converted" select="ClosingCapital div ../@XRate"></xsl:variable>
<tr>
<td>
<xsl:value-of select="@Description" />
</td>
<td>
<xsl:value-of select="ValuationDate" />
</td>
<td align="right">
<xsl:value-of select="format-number(ClosingCapital
, '###,##0')" />
</td>
<td align="right">
<xsl:value-of select="format-number(ClosingCapital
div XRate, '###,##0')" />
</td>
<td align="right">
TODO
</td>
</tr>
</xsl:for-each>
<tr>
<td colspan="2">Total <xsl:value-of select="@Description"/></td>
<td align="right">
<xsl:value-of select="format-number(sum($FundTotal
), '###,##0')" />
</td>
<td align="right">
TODO
</td>
<td align="right">TODO</td>
</tr>
</xsl:for-each>
<tr>
<td colspan="2">
Grand Total <xsl:value-of select="@Description"/>
</td>
<td align="right">
<xsl:value-of select="format-number(sum(//NAV/Fund
s/Fund/Sub
Fund/Closi
ngCapital)
, '###,##0')" />
</td>
<td align="right">
TODO
</td>
<td align="right">TODO</td>
</tr>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
I need to add to this XSL file:
-the total by Fund of the Closing Capital (Converted) column
-the grand total for all funds of the Closing Capital (Converted) column
-calculate the % of Grand total column (which is the Closing Capital (Converted) value / Grand Total converted
Any ideas?