Subject: [xsl] Recursive template, pattern matching, summing result From: Steve <subsume@xxxxxxxxx> Date: Thu, 7 Sep 2006 13:08:53 -0400 |
What I am doing is looping through records, grabbing the expenses associated with the currrnet record with the document() function, using substring() to test whether the expense contains "mileage". If any (0,1 or more expenses) are "mileage", split it up (using fxsl strSplit-to-Words) and get the number of miles and move to the next record.
Now since I'm not looping through the expenses, but the records and then the checking the expenses, the template can't simply call itself for each expense that contains "mileage".
Currently, I can isolate the mileage but I'm not sure how to do this twice, sum them up, and then pass the total along to the template. Perhaps this is a job for xsl:key?
<xsl:template mode="totalExpense" match="Record"> <xsl:param name="mileage">0</xsl:param> <xsl:variable name="expenses" select="document(concat($getXML,'table=Activity_Expenses&key=actID&val=',id))/Records/Record" /> <xsl:choose> <xsl:when test="following-sibling::Record[1]"> <xsl:variable name="miles"> <xsl:call-template name="str-split-to-words"> <xsl:with-param name="pStr" select="msxsl:node-set($expenses[substring(expense,1,7)='mileage']/expense)" /> <xsl:with-param name="pDelimiters" select="' '" /> <!-- a blank space--> </xsl:call-template> </xsl:variable> <xsl:value-of select="msxsl:node-set($miles)/*[2]" /><br /> <xsl:apply-templates mode="totalExpense" select="following-sibling::Record[1]"> <xsl:with-param name="mileage" select="$mileage + *the sum of miles totalled in this iteration * " /> </xsl:apply-templates> </xsl:when> <xsl:otherwise> Total mileage: $<xsl:value-of select="format-number($mileage,'#,00')" /> </xsl:otherwise> </xsl:choose> </xsl:template>
<Records> <Record> <expense>Mileage: 10 @ .445/mi</expense> <!-- I need the 10 here--> <cost>4.45</cost> </Record> <Record> <expense>Mileage: 10 @ .445/mi</expense> <cost>4.45</cost> </Record> </Records>
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] Grouping using group-star, G. Ken Holman | Thread | [xsl] xsl template priority / xsl t, Ralph Rauscher |
Re: [xsl] blank page formatting, Danny Vint | Date | RE: [xsl] Grouping using group-star, Michael Kay |
Month |