Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   XML (http://www.velocityreviews.com/forums/f32-xml.html)
-   -   XSL Question tp xsl:for-each and xsl:variable (http://www.velocityreviews.com/forums/t169386-xsl-question-tp-xsl-for-each-and-xsl-variable.html)

schaf@2wire.ch 05-27-2005 01:32 PM

XSL Question tp xsl:for-each and xsl:variable
 
Hello NG !
I have a big problem.
I would like to go through a xml file in a xsl:for-each statement.
for-each entry (ID) in the XML file i would like to call an
xsl:function, which returns a number. This number i have to summarize
during the whole for-each statement. At the end i should have the sum
of the added numbers.

Like:

int sum;
for(int i = 0; i <= 10; ++i)
{
sum += i;
}

I tried like this, but it does not work, becasue an xsl:variable could
be set just once:

<xsl:function name="rsh:bestanden">
<xsl:param name="kursTyp" as="xs:string"/>
<xsl:param name="studiumTyp" as="xs:string"/>
<xsl:variable name="minPunkte"
select="$study-def/studium[@studiumID=studiumTyp]/studiumTeil[@studiumTeilID=$kursTyp]/ECTSPunkte"/>
<xsl:variable name="summeECTSPunkts"/>

<xsl:for-each
select="$study-def/studium[@studiumID=studiumTyp]/studiumTeil[@studiumTeilID=$kursTyp]/kursRef">
<xsl:variable name="kursID" select="@ref"/>
<xsl:variable name="kursNote"
select="rsh:noteByKursID($kursID)"/>
<xsl:if test="$kursNote != 'F'">
=>??? $summeECTSPunkte = $summeECTSPunkte +
rsh:punkteByKursID($kursID)
</xsl:if>
</xsl:for-each>


Thanks for help
regards
Marcel


A. Bolmarcich 05-27-2005 09:25 PM

Re: XSL Question tp xsl:for-each and xsl:variable
 
On 2005-05-27, schaf@2wire.ch <schaf@2wire.ch> wrote:
> I would like to go through a xml file in a xsl:for-each statement.
> for-each entry (ID) in the XML file i would like to call an
> xsl:function, which returns a number. This number i have to summarize
> during the whole for-each statement. At the end i should have the sum
> of the added numbers.

[snip]

Since you are using XSLT 2 (you used xls:function in the XSLT snippet),
use a for-each to set the value of a xslt variable to a temporary tree
whose elements contain the values to sum.

Using parts of your snippet

<xsl:variable name="tt-to-sum">
<v>0</v> <!-- avoid having an empty tree -->
<xsl:for-each select="*your select expression*">
<xsl:variable name="kursID" select="@ref"/>
<xsl:variable name="kursNote" select="rsh:noteByKursID($kursID)"/>
<xsl:if test="$kursNote != 'F'">
<v><xsl:value-of select="rsh:punkteByKursID($kursID)'/></v>
</xsl:if>
</xsl:for-each>
</xsl:variable>

The expression sum($tt-to-sum/*) is the sum of the values.


All times are GMT. The time now is 09:02 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.