Bonjour!
My last example seemed to cause some misunderstandings, so I worked on a better one. Here it comes:
I have an XML file with the names of players.
With the following XSLT file I want to initialize each player with a random numeric value und send it to the output. The last line should contain the sum of all initial values.
The output should look like this
How can I calculate the sum of the random numbers
Thanks for help
Tschuri
Edited by Tschuri (08 May 2005 - 11:08)
My last example seemed to cause some misunderstandings, so I worked on a better one. Here it comes:
I have an XML file with the names of players.
<?xml version="1.0" encoding="UTF-8"?>
<doc>
<data number="1" type="x">herbert</data>
<data number="2">joe</data>
<data number="3">jean-jacques</data>
</doc>
With the following XSLT file I want to initialize each player with a random numeric value und send it to the output. The last line should contain the sum of all initial values.
<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<xsl:variable name="seed" select="2"/>
<html>
<body>
<table border="1">
<tr>
<th>Name</th>
<th>Inital Value</th>
</tr>
<xsl:for-each select="/doc/data">
<tr>
<td>
<xsl:value-of select="."/>
</td>
<td><!-- this is a (very poor) pseudo-random function. think of it as a real random function -->
<xsl:value-of select="substring(substring-after($seed div (position()*string-length ()), '.'),2, 3)"/>
</td>
</tr>
</xsl:for-each>
<tr>
<td>sum</td>
[color=red]<td>????</td> > <!-- how do i calculate the sum ? -->[/color]
</tr>
</table>
</body>
</html>
</xsl:template>
<xsl:template match="*|@*|text()">
</xsl:template>
</xsl:stylesheet>
The output should look like this
<html>
<body>
<table border="1">
<tr><td>herbert</td><td>857</td></tr>
<tr><td>joe</td><td>333</td></tr>
<tr><td>jean-jacques</td><td>555</td></tr>
<tr><td>Sum</td><td>1745</td></tr>
</table>
</body>
</html>
How can I calculate the sum of the random numbers
Thanks for help
Tschuri
Edited by Tschuri (08 May 2005 - 11:08)