|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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 |
|
#2
|
|||
|
|||
|
Variable code should look like this I think...
Code:
<xsl:variable name="total" select="sum(Accounts/BrokerageAccount[@MoneyAccountValue])" />
__________________
Best regards Darren |
|
#3
|
|||
|
|||
|
Darren,
The piece of code u suggested didn't worked.... Thanks, Kalpana |
|
#4
|
|||
|
|||
|
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 |
|
#5
|
||||
|
||||
|
How can I accomplish this sum, if the data is between <moneyvalue> tags, instead of an attribute moneyvalue="2.00"?
__________________
Hello, old friend... |
|
#6
|
||||
|
||||
|
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)" /> |
|
#7
|
||||
|
||||
|
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? |
|
#8
|
||||
|
||||
|
Try this my friend:
Code:
<xsl:variable name="total" select="sum(number(Accounts/BrokerageAccount/moneyvalue))" /> |
|
#9
|
||||
|
||||
|
Ah, I tried that and got this error:
ERROR: Description: Argument 1 must return a node-set. |
|
#10
|
||||
|
||||
|
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.
|
|
#11
|
||||
|
||||
|
I feel so dumb. This will work, I tested it.
Code:
select="sum(Accounts/BrokerageAccount[moneyvalue != '']/moneyvalue)" |
|
#12
|
||||
|
||||
|
You rock!!!
|
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > XML Programming > sum function in XSL |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|