473,802 Members | 2,017 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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:besta nden">
<xsl:param name="kursTyp" as="xs:string"/>
<xsl:param name="studiumTy p" as="xs:string"/>
<xsl:variable name="minPunkte "
select="$study-def/studium[@studiumID=stud iumTyp]/studiumTeil[@studiumTeilID= $kursTyp]/ECTSPunkte"/>
<xsl:variable name="summeECTS Punkts"/>

<xsl:for-each
select="$study-def/studium[@studiumID=stud iumTyp]/studiumTeil[@studiumTeilID= $kursTyp]/kursRef">
<xsl:variable name="kursID" select="@ref"/>
<xsl:variable name="kursNote"
select="rsh:not eByKursID($kurs ID)"/>
<xsl:if test="$kursNote != 'F'">
=>??? $summeECTSPunkt e = $summeECTSPunkt e +
rsh:punkteByKur sID($kursID)
</xsl:if>
</xsl:for-each>
Thanks for help
regards
Marcel

Jul 20 '05 #1
1 1611
On 2005-05-27, sc***@2wire.ch <sc***@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:not eByKursID($kurs ID)"/>
<xsl:if test="$kursNote != 'F'">
<v><xsl:value-of select="rsh:pun kteByKursID($ku rsID)'/></v>
</xsl:if>
</xsl:for-each>
</xsl:variable>

The expression sum($tt-to-sum/*) is the sum of the values.
Jul 20 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
2530
by: xmlhelp | last post by:
stuff.XSL: <?xml version="1.0" encoding="ISO-8859-1"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:param name="uid"/> <xsl:template match="/"> parameter UID=<xsl:value-of select="$uid"/> <table border="1"> <tr> <xsl:for-each select="row/value=20]">
0
9699
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9562
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10538
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10305
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10285
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10063
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6838
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5622
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2966
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.