Subject: RE: [xsl] Adding subtotals to a report From: "Michael Kay" <michael.h.kay@xxxxxxxxxxxx> Date: Fri, 19 Apr 2002 10:19:36 +0100 |
> 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 |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Adding subtotals to a rep, J.Pietschmann | Thread | RE: [xsl] Adding subtotals to a rep, David Messing 477-1 |
[xsl] Evaluating a temporary NodeSe, Florian Mansmann | Date | RE: [xsl] Replacing images with alt, Michael Kay |
Month |