Re: [xsl] Count all the elements of a column

Subject: Re: [xsl] Count all the elements of a column
From: "Jorge A. Salido" <jorgesalido@xxxxxxxxx>
Date: 14 Nov 2002 14:11:32 -0600
Hi

You have to use a recursive template in order to accumulate the number.
Do something like:

(you have to set up the number of agents in the total parameter - count
them with the count function)

<xsl:template name="sum">
	<xsl:param name="current" select="1"/>
	<xsl:param name="counter" select=""/>
	<xsl:param name="total" select="0"/>
	<xsl:choose>
		<xsl:when test="$current = $total">
			<xsl:value-of select="$counter + //agent[$current]/codenet"/>
		</xsl:when>
		<xsl:otherwise>
			<xsl:call-template name="sum">
				<xsl:with-param name="counter" select="$counter +
//agent[$current]/codenet"/>
				<xsl:with-param name="current" select="$current + 1"/>
				<xsl:with-param name="total" select="$total"/>
			</xsl:call-template>
		</xsl:otherwise>
	</xsl:choose>
</xsl:template>


On Thu, 2002-11-14 at 11:55, Yann Verlynde wrote:
> sorry I use this xml file structure:
> <agent id="058">
> 
> <datenaissance>27/02/1977</datenaissance>
> 
> <sexe>F</sexe>
> 
> <cadreemploi>emploi8</cadreemploi>
> 
> <codenet>8</codenet>
> 
> <specialite>specialite8</specialite>
> 
> <discipline>discipline8</discipline>
> 
> <datedebut>8/01/1977</datedebut>
> 
> </agent>
> 
> <agent id="059">
> 
> <datenaissance>27/02/1977</datenaissance>
> 
> <sexe>M</sexe>
> 
> <cadreemploi>emploi9</cadreemploi>
> 
> <codenet>9</codenet>
> 
> <specialite>specialite9</specialite>
> 
> <discipline>discipline9</discipline>
> 
> <datedebut>9/01/1977</datedebut>
> 
> </agent>
> 
> 
> 
> My table is constructed by a for-each tag and I want to sum all codenet
> Attribute
> 
> 
> 
> Thanks
> 


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


Current Thread