[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: Adding subtotals to a report

Subject: RE: Adding subtotals to a report
From: "Michael Kay" <michael.h.kay@xxxxxxxxxxxx>
Date: Fri, 19 Apr 2002 10:19:36 +0100
xsl subtotals
> 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@xxxxxxxxxxxx
work: Michael.Kay@xxxxxxxxxxxxxx

> <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


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.