XML - XPath Help Please

Joined
Nov 18, 2008
Messages
1
Reaction score
0
Hi, I am doing quite a simple XPath query and am not to sure how to go about it.

I have the following XML structure:

<?xml version="1.0"?><!DOCTYPE transactions []>
<transactions>
<transaction date="05/22/2000" id="0122">
<from account="100392"/>
<to account="203921"/>
<amount currency="USD">15</amount>
</transaction>
<transaction date="06/01/2000" id="0129">
<from account="203921"/>
<to account="877521"/>
<amount currency="USD">4800</amount>
</transaction>
<transaction date="06/01/2000" id="0130">
<from account="100392"/>
<to account="992031"/>
<amount currency="YEN">7000</amount>
</transaction>
<transaction date="06/10/2000" id="0152">
<from account="992031"/>
<to account="100392"/>
<amount currency="USD">402.53</amount>
</transaction>
<transaction date="06/22/2000" id="0188">
<from account="100392"/>
<to account="203921"/>
<amount currency="USD">10000</amount>
</transaction>
<transaction date="07/12/2000" id="0200">
<from account="100392"/>
<to account="039211"/>
<amount currency="NTD">3000</amount>
</transaction>
<transaction date="07/26/2000" id="0211">
<from account="203921"/>
<to account="100392"/>
<amount currency="USD">400</amount>
</transaction>
<transaction date="08/05/2000" id="0225">
<from account="039211"/>
<to account="203921"/>
<amount currency="USD">150</amount>
</transaction>
<transaction date="09/03/2000" id="0293">
<from account="100392"/>
<to account="039211"/>
<amount currency="NTD">200000</amount>
</transaction></transactions>


I wanted to find the amount account #203921 has, so i Did the following:

sum(/transactions/transaction[to/@account="203921"]/self::*/number(amount))

Which works, but now I want to get the 'average' How can this be done? I know I have to div by 3 but I don't want to type .... div 3. I want it to count the nodes and div by that value. However, I have no clue how. I cant search back from the node i.e /parent::* etc.. I'm unsure how to go about it, any help appreciated!

Thank you.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,073
Latest member
DarinCeden

Latest Threads

Top