[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Recursive template, pattern matching, summing result
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 goes: (Recursive template, passed only the first Record/calling itself) <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> $expenses contains: <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>
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|