xsl-list
[Top] [All Lists]

reccursive sum ?

2004-03-02 03:39:25
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



<Prev in Thread] Current Thread [Next in Thread>