This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
RE: Adding subtotals to a report
- From: "Michael Kay" <michael dot h dot kay at ntlworld dot com>
- To: <xsl-list at lists dot mulberrytech dot com>
- Date: Fri, 19 Apr 2002 10:19:36 +0100
- Subject: RE: [xsl] Adding subtotals to a report
- Reply-to: xsl-list at lists dot mulberrytech dot com
> If I apply the following XSL to it:
>
> <xsl:template match="ScheduleVariance">
> <table cellpadding="3" width="100%">
> <xsl:for-each select="Project">
> <tr bgcolor="darkslateblue">
> <td colspan="2"><b><font color="gold"><xsl:value-of
> select="@ProjectName"/></font></b></td>
> <td><font color="gold"><b>Start</b></font></td>
> <td><font color="gold"><b>End</b></font></td>
> <td><font color="gold"><b>Lunch</b></font></td>
> <td><font color="gold"><b>Break</b></font></td>
> <td><font color="gold"><b>Total</b></font></td>
> <xsl:for-each select="Employee">
> <xsl:variable name="subtotals">
> <subtotal><xsl:value-of select="Total"
> /></subtotal>
> </xsl:variable>
> <tr>
> <xsl:call-template name="Employee" />
> </tr>
> </xsl:for-each>
> <tr>
> <xsl:call-template name="FooterRow" />
> </tr>
> </tr>
> </xsl:for-each>
> </table>
> </xsl:template>
>
> I get the report formatted the way they want it, but when I
> try to add this to it to get subtotals, I get variable is not
> defined or in scope.
>
> <xsl:call-template name="SubtotalRow" >
> <xsl:with-param name="subtotals" select="$subtotals"/>
> </xsl:call-template>
You haven't said where you added this. Since the error message was "variable
out of scope", you presumably didn't add it within the scope of the
$subtotals variable.
But there are two other problems. Firstly, you've declared the variable as a
result tree fragment, and are then trying to get inside it using a path
expression. You can't do this without the node-set() extension. Why not just
declare the variable as <xsl:variable name="subtotals" select="Total"/>
But that leads to the question, what do you expect to output as the
"subtotal"? I can't see where you are doing any calculation of a subtotal.
Michael Kay
Software AG
home: Michael.H.Kay@ntlworld.com
work: Michael.Kay@softwareag.com
> <xsl:template name="SubtotalRow">
> <xsl:param name="subtotals" select="/.."/>
> <tr>
> <td></td>
> <td><b>Totals</b></td>
> <td></td>
> <td></td>
> <td></td>
> <td></td>
> <td></td>
> <td><xsl:value-of select="sum($subtotals/subtotal)" /></td>
> </tr>
> </xsl:template>
>
> I thought I could pass the variable I'm creating above to
> this template, but it's not working. Is there an easier way
> to calculate subtotals or is there an error in my stylesheet?
>
> David Messing
>
>
> XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
>
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list