XML Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreXML Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old March 26th, 2003, 05:30 PM
kalpana_kk kalpana_kk is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2003
Posts: 11 kalpana_kk User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Question sum function in XSL

Hi all,

I am tryig to find the sum of "MoneyAccountValue". But I donot get anykind of o/p nor i get anykind of error.

Here is the XSL code...

Total : <xsl:variable name="total" select="sum(Accounts/BrokerageAccount/@MoneyAccountValue)" />


and the XML code is...........


<Accounts>
<BrokerageAccount Name="Account1" Number="1234" Registration="CMA Direct" MoneyAccountValue="1000" />
<BrokerageAccount Name="Account2" Number="1235" Registration="IRA" MoneyAccountValue="1000" />

</Accounts>


I would appreciate if someone can find the reason....

THanks
Kalpana

Reply With Quote
  #2  
Old March 27th, 2003, 03:04 AM
DarrenJ DarrenJ is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2003
Posts: 42 DarrenJ User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 m 21 sec
Reputation Power: 6
Variable code should look like this I think...

Code:
<xsl:variable name="total" select="sum(Accounts/BrokerageAccount[@MoneyAccountValue])" />
__________________
Best regards
Darren

Reply With Quote
  #3  
Old March 27th, 2003, 10:58 AM
kalpana_kk kalpana_kk is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2003
Posts: 11 kalpana_kk User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Question

Darren,

The piece of code u suggested didn't worked....

Thanks,
Kalpana

Reply With Quote
  #4  
Old March 27th, 2003, 11:22 AM
kalpana_kk kalpana_kk is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2003
Posts: 11 kalpana_kk User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Unhappy

I think i know what mistake i did...i didn't tried to display the vairable 'total'

<xsl:variable name="total" select="sum(Accounts/BrokerageAccount/@MoneyAccountValue)" /> <xsl:value-of select="$total"/>

Thanks much,
Kalpana

Reply With Quote
  #5  
Old February 11th, 2004, 11:04 AM
khwang's Avatar
khwang khwang is offline
Über nübe
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Location: Babylon 4
Posts: 240 khwang User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 29 m 27 sec
Reputation Power: 6
How can I accomplish this sum, if the data is between <moneyvalue> tags, instead of an attribute moneyvalue="2.00"?
__________________
Hello, old friend...

Reply With Quote
  #6  
Old February 11th, 2004, 04:41 PM
MattSidesinger's Avatar
MattSidesinger MattSidesinger is offline
Java PHP Oracle Developer
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Location: C-Bus OH-IO
Posts: 204 MattSidesinger User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 15 m 26 sec
Reputation Power: 5
Send a message via AIM to MattSidesinger
khwang,

To answer your question, assuming the xml looks as follows:
Code:
<Accounts>
     <BrokerageAccount Name="Account1" Number="1234" Registration="CMA Direct">
          <moneyvalue>2.00</moneyvalue>
     </BrokerageAccount>
     <BrokerageAccount Name="Account2" Number="1235" Registration="IRA">
          <moneyvalue>2.00</moneyvalue>
     </BrokerageAccount>
</Accounts>


would be:
Code:
<xsl:variable name="total" select="sum(Accounts/BrokerageAccount/moneyvalue)" />

Reply With Quote
  #7  
Old February 11th, 2004, 06:48 PM
khwang's Avatar
khwang khwang is offline
Über nübe
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Location: Babylon 4
Posts: 240 khwang User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 29 m 27 sec
Reputation Power: 6
Following your response, let's say one of the moneyvalue fields is left blank:

Code:
<Accounts>
     <BrokerageAccount Name="Account1" Number="1234" Registration="CMA Direct">
          <moneyvalue></moneyvalue>
     </BrokerageAccount>

... etcetera ...

</Accounts>


Then when I try to get sum, the result is NaN. Is there any workaround for this?

Reply With Quote
  #8  
Old February 12th, 2004, 08:52 AM
MattSidesinger's Avatar
MattSidesinger MattSidesinger is offline
Java PHP Oracle Developer
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Location: C-Bus OH-IO
Posts: 204 MattSidesinger User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 15 m 26 sec
Reputation Power: 5
Send a message via AIM to MattSidesinger
Try this my friend:

Code:
<xsl:variable name="total" select="sum(number(Accounts/BrokerageAccount/moneyvalue))" />

Reply With Quote
  #9  
Old February 12th, 2004, 10:33 AM
khwang's Avatar
khwang khwang is offline
Über nübe
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Location: Babylon 4
Posts: 240 khwang User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 29 m 27 sec
Reputation Power: 6
Ah, I tried that and got this error:

ERROR: Description: Argument 1 must return a node-set.

Reply With Quote
  #10  
Old February 12th, 2004, 10:50 AM
MattSidesinger's Avatar
MattSidesinger MattSidesinger is offline
Java PHP Oracle Developer
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Location: C-Bus OH-IO
Posts: 204 MattSidesinger User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 15 m 26 sec
Reputation Power: 5
Send a message via AIM to MattSidesinger
OK, I didn't test that. That sounds about right. I am at training right now ... haha. I will try some stuff when I get back to the office. Sorry I am of no help without my trusty transformer.

Reply With Quote
  #11  
Old February 16th, 2004, 02:12 PM
MattSidesinger's Avatar
MattSidesinger MattSidesinger is offline
Java PHP Oracle Developer
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Location: C-Bus OH-IO
Posts: 204 MattSidesinger User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 15 m 26 sec
Reputation Power: 5
Send a message via AIM to MattSidesinger
I feel so dumb. This will work, I tested it.

Code:
select="sum(Accounts/BrokerageAccount[moneyvalue != '']/moneyvalue)"

Reply With Quote
  #12  
Old February 16th, 2004, 02:21 PM
khwang's Avatar
khwang khwang is offline
Über nübe
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Location: Babylon 4
Posts: 240 khwang User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 29 m 27 sec
Reputation Power: 6
You rock!!!

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreXML Programming > sum function in XSL


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
Stay green...Green IT