Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
| Search | Today's Posts | Mark Forums Read
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
  #1 (permalink)  
Old October 2nd, 2006, 07:12 AM
Registered User
 
Join Date: Oct 2006
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default how to sum in for-each

Hello.

Im trying to sum all the "poeng" elements from the xml file.

 <test>
    <oppgave nr="1">
      <svar>c</svar>
      <poeng>3</poeng>
    </oppgave>
    <oppgave nr="2">
      <svar>b</svar>
      <poeng>-1</poeng>
      <kommentar>error</kommentar>
    </oppgave>
    <oppgave nr="3">
      <svar>b</svar>
      <poeng>3</poeng>
    </oppgave>
    <oppgave nr="4">
      <svar>a</svar>
      <poeng>0</poeng>
    </oppgave>
    <oppgave nr="5">
      <svar>c</svar>
      <poeng>3</poeng>
    </oppgave>
  </test>

so in XSL I have this for-each:

<xsl:for-each select="test/oppgave">
 sum(poeng)
</xsl:for-each>

--> get the sum here



  #2 (permalink)  
Old October 2nd, 2006, 08:48 AM
mhkay's Avatar
Wrox Author
Points: 18,487, Level: 59
Points: 18,487, Level: 59 Points: 18,487, Level: 59 Points: 18,487, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

If you want a single sum for the whole source document, that's sum(/test/oppgave/poeng). Doing the sum() inside a for-each would only be appropriate if you want multiple totals (ie. subtotals).

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to sum satish_baleri XSLT 6 October 24th, 2007 03:43 AM
Help: Running Sum (or Cumulative Sum) timdasa VB Databases Basics 1 August 22nd, 2006 03:12 PM
sum utarian Access 2 March 28th, 2005 09:42 PM
need sum help! jbik BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 0 December 20th, 2004 05:27 PM
SUM or What bertlf Pro VB Databases 2 November 29th, 2003 02:44 PM





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