Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 8th, 2005, 04:14 AM
Registered User
 
Join Date: May 2005
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Sum of random numbers in a table with XSLT

Hello!

I have an XML file with the names of players.
Code:
<?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.
Code:
<?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>
              <xsl:value-of select="substring(substring-after($seed div (position()*string-length     ()), '.'),2, 3)"/>              
            </td>
          </tr>
         </xsl:for-each>
         <tr>
           <td>sum</td>
            <td>????</td> > 
         </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

herpes





Similar Threads
Thread Thread Starter Forum Replies Last Post
how to generate random numbers in xslt anboss XSLT 3 July 23rd, 2008 09:10 AM
Random Numbers Using MersenneTwister JoeDW C# 0 September 13th, 2006 11:10 AM
Random Numbers welshboy2005 C# 1 May 19th, 2005 06:01 AM
random numbers from/to database HammR PHP Databases 10 January 14th, 2005 12:08 PM
Random Numbers not so random... katsarosj ASP.NET 1.0 and 1.1 Basics 5 November 20th, 2003 12:55 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.