This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Adding subtotals to a report


I posted this once before but didn't get any response.. so I'll try rephrasing my request..

I've got the following XML file being outputted from a database:

<ScheduleVariance>
<Project ProjectName="Sales">
<Employee EmpID="513" EmpName="Smith, John" SchedStart="Not Scheduled" ActualStart="Mar 20 2002  8:57AM" StartDiff="0" SchedEnd="Not Scheduled" ActualEnd="Mar 20 2002  7:58PM" EndDiff="0" SchedLunchLen="0" ActualLunchLen="0" LunchDiff="0" SchedBreakLen="0" ActualBreakLen="0" BreakDiff="0" SchedLen="0" ActualLen="661" Total="661"/>
<Employee EmpID="781" EmpName="Doe, John" SchedStart="Not Scheduled" ActualStart="Mar 20 2002  9:00AM" StartDiff="0" SchedEnd="Not Scheduled" ActualEnd="Mar 20 2002  4:30PM" EndDiff="0" SchedLunchLen="0" ActualLunchLen="60" LunchDiff="-60" SchedBreakLen="0" ActualBreakLen="0" BreakDiff="0" SchedLen="0" ActualLen="390" Total="390"/>
</Project>
<Project ProjectName="Customer Service">
<Employee EmpID="235" EmpName="Doe, Jane" SchedStart="Not Scheduled" ActualStart="Did Not Work" StartDiff="0" SchedEnd="Not Scheduled" ActualEnd="Did Not Work" EndDiff="0" SchedLunchLen="0" ActualLunchLen="0" LunchDiff="0" SchedBreakLen="0" ActualBreakLen="0" BreakDiff="0" SchedLen="0" ActualLen="0" Total="0"/>
<Employee EmpID="240" EmpName="Test, John" SchedStart="Mar 20 2002 11:00AM" ActualStart="Mar 20 2002 11:07AM" StartDiff="-7" SchedEnd="Mar 20 2002  8:00PM" ActualEnd="Mar 20 2002  8:02PM" EndDiff="2" SchedLunchLen="0" ActualLunchLen="0" LunchDiff="0" SchedBreakLen="0" ActualBreakLen="0" BreakDiff="0" SchedLen="540" ActualLen="535" Total="-5"/>
<Employee EmpID="104" EmpName="Test, Jim" SchedStart="Mar 20 2002 11:00AM" ActualStart="Did Not Work" StartDiff="0" SchedEnd="Mar 20 2002  8:00PM" ActualEnd="Did Not Work" EndDiff="0" SchedLunchLen="0" ActualLunchLen="0" LunchDiff="0" SchedBreakLen="0" ActualBreakLen="0" BreakDiff="0" SchedLen="540" ActualLen="0" Total="-540"/>
</Project>
</ScheduleVariance>

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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]