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

reccursive sum ?

Subject: reccursive sum ?
From: "Ricaud Matthieu" <matthieu.ricaud@xxxxxxx>
Date: Tue, 2 Mar 2004 11:39:25 +0100
xsl calculate sum
For each "ME" node in LIST.xml, i calculate the number of "devoirs". To do
so I must open each MATIERE.XML and making a count of all "DEVOIR" nodes.

LIST.xml looks like this :

<LISTE-ME>
	<ME id="0010"/>
	<ME id="0045"/>
	<ME id="0152"/>
</LISTE-ME>

Each ME has a description in his own file, for instance the file 0010.xml
looks like this :

<ME ref="0010">
	<FOURN label="anything">
		<DEVOIR name="anything">
		<DEVOIR name="anything">
	</FOURN>
	<FOURN label="anything">
		<DEVOIR name="anything">
		<DEVOIR name="anything">
		<DEVOIR name="anything">
	</FOURN>
</ME>

The XSL apply on LIST.xml looks like this :

<xsl:template match="LISTE-ME">
	<xsl:for-each select="ME">
		<xsl:variable name="ThisMEid">
			<xsl:value-of select="@id"/>
		</xsl:variable>
		ME <xsl:value-of select="@id"/> :
		<xsl:call-template name="NbreDevoirsME">
			<xsl:with-param name="MEid" select="$ThisMEid"/>
		</xsl:call-template>
		 devoirs <br/>
	<xsl:for-each/>
</xsl:template>

<xsl:template name="NbreDevoirsME">
	<xsl:param name="MEid"/>
	<xsl:variable name="MEfile">
		<xsl:value-of select="$MEid">.xml
	</xsl:variable>
	<xsl:value-of select="count(document($MEfile)/ME/FOURN/DEVOIR"/>
</xsl:template>

The Output would be here something like this :

ME 0010 : 5 devoirs
ME 0045 : 3 devoirs
ME 0152 : 7 devoirs

What i'd like is the total number of devoirs for all ME. ==> TOTAL = 15
devoirs

At this point I do not manage anymore :

* I m pretty sure the solution must be a reccursive template, but i did not
find it ...
* I thought about a way to calculate this sum :
	if I write <xsl:value-of select="5+3+7">, it gives 15.
	So I put in a variable "string" the expression to be calculated :

					<xsl:variable name="String">
						<xsl:for-each select="ME">
							<xsl:variable name="ThisMEid">
								<xsl:value-of select="@id"/>
							</xsl:variable>
							<xsl:call-template name="NbreDevoirsME">
								<xsl:with-param name="MEid" select="$ThisMEid"/>
							</xsl:call-template>
							<xsl:if test="position()!=last()">
							+
							</xsl:if>
						</xsl:for-each>
					</xsl:variable>

	Off course, when I write <xsl:value-of select="$String"/> the processor
don't calculate it, it just dysplay the string.
	Is there a way to tell him, $string must be interpreted as a Xpath
expression which you must calculate ?





 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


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.