wood burning stoves 2.0*
The moose likes XML and Related Technologies and the fly likes How to sum from 2 fields? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "How to sum from 2 fields?" Watch "How to sum from 2 fields?" New topic
Author

How to sum from 2 fields?

Ong Vua
Ranch Hand

Joined: Jan 24, 2008
Posts: 59
Here's my xml



I want to sum the total sale prices, in this case it will be $14 because the 1st one does not sell any ticket

The simplest way I think of is to multiple price with sold for each ticket and then sum it all up.

I group by <ticket> and below is my code but I got 0

<?sum(current-group()/sold * current-group()/price)?>

Do you know why? If you have a simpler approach, please let me know

Thanks
Ong Vua
Ranch Hand

Joined: Jan 24, 2008
Posts: 59
One more thing, the <sold></sold> tag will only have 2 values (1 or 0)
g tsuji
Ranch Hand

Joined: Jan 18, 2011
Posts: 510
    
    3
<?sum(current-group()/sold * current-group()/price)?>

What is it? Where do you learn this syntax, remotely like a processing-instruction but not being one?

I group by <ticket>

Suppose you mean what you say and thereby you mean you're working with xslt 2.0 as well.
One more thing, the <sold></sold> tag will only have 2 values (1 or 0)

If you do thing right, it does not generically matter.

Here is how at the current-group() (xslt 2.0) of what you said you have grouped.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: How to sum from 2 fields?