[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Recursive template, pattern matching, summing result

Subject: Recursive template, pattern matching, summing result
From: Steve <subsume@xxxxxxxxx>
Date: Thu, 7 Sep 2006 13:08:53 -0400
template pattern
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&amp;key=actID&amp;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>

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.