RE: [xsl] Adding subtotals to a report

Subject: RE: [xsl] Adding subtotals to a report
From: "David Messing 477-1289" <DMessing@xxxxxxxxxxxxxxxxxxx>
Date: Fri, 19 Apr 2002 09:17:46 -0700
What I was trying to do was look for a Project element which has an attribute named ProjectName and the value is equal to the current ProjectName attribute.  When I tried putting current() in there like so:

<xsl:value-of select="sum(/*/Project[current()]/*/@Total)" />

It gives me the same result as if I had used last().

Here's a slimmed down version of the XML File.

<ScheduleVariance>
<Project ProjectName="Sales">
<Employee EmpID="317" EmpName="Doe, Jane" SchedLen="9:00" ActualLen="9:33" TotalDiff="0:33"/>
<Project ProjectName="Customer Service">
<Employee EmpID="174" EmpName="Smith, Chris" SchedLen="9:00" ActualLen="8:01" TotalDiff="-0:59"/>
</Project>
</ScheduleVariance>

Inside a for-each Project, I need to add up all of the "Employee/TotalDiff" attributes for the current project and insert the total as a new row at the bottom.  Once I get one total working, I can replicate the process for other totals I need on the same row.

-----Original Message-----
From: Michael Kay [mailto:michael.h.kay@xxxxxxxxxxxx]
Sent: Friday, April 19, 2002 2:31 AM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: RE: [xsl] Adding subtotals to a report


> When I try summing the totals directly I get 0.
>
> I can do this
> <xsl:value-of select="sum(/*/*/*/@Total)" />
> to get an overall total for the document.
>
> When I try to do this:
> <xsl:value-of select="sum(/*/Project[ProjectName =
> @ProjectName]/*/@Total)" />
>
> I get 0 again.  I know the data is there, I just need a
> little help getting to it.

I haven't kept your XML file and it was pretty impenetrable anyway, but the
above is looking for a <Project> element that has a child ProjectName and an
attribute ProjectName, both of which are equal to each other - which would
seem an unlikely condition. I suspect one of these (either the child or the
attribute) should be prefixed as "current()/", but I don't understand your
data well enough to be sure. Send us a simplified version.

Michael Kay
Software AG
home: Michael.H.Kay@xxxxxxxxxxxx
work: Michael.Kay@xxxxxxxxxxxxxx
>
> -----Original Message-----
> From: J.Pietschmann [mailto:j3322ptm@xxxxxxxx]
> Sent: Thursday, April 18, 2002 4:51 PM
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: Re: [xsl] Adding subtotals to a report
>
>
> David Messing 477-1289 wrote:
> > <xsl:template match="ScheduleVariance">
> ...
> > 		<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>
> ...
> > 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.
>
> That's because the variable is not in scope. The scope
> of variables is the enclosing element, in this case
> the for-each statement working on your Employee elements.
>
> Why don't you access the totals directly?
>
>   <tr>
>   	<td></td>
>   	<td><b>Totals</b></td>
>   	<td></td>
>   	<td></td>
>   	<td></td>
>   	<td></td>
>   	<td></td>
>   	<td><xsl:value-of select="sum(Employee/Total)" /></td>
>   </tr>
>
> J.Pietschmann
>
>
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
>
>
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
>


 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