Question about aggregating attributes in XML

M

manojas

Hi

I am new to XQuery and i am trying to figure out a way to solve the
following

I have an XML document as shown below



<Root>

<Function Name="foo" Time="1" Count="1">

<Function Name="bar" Time="3" Count="1">

<Event Duration="5"/>

</Function>

</Function>

<Function Name="foo" Time="7" Count="2">

<Function Name="bar" Time="11" Count="2">

<Event Duration="13"/>

</Function>

</Function>

<Function Name="bar" Time="19" Count="3">

<Event Duration="23"/>

</Function>

</Root>



I need the following resultset:



Function Sum(Time) Sum(Duration)

foo 8 (7+1) 0

bar 33 (3+11+19) 41 (5+13+23)



I am not sure how to project out the child nodes value aggregates (the
3rd column in the desired resultset)



Sum(Time) - Represents aggregate of the Time attribute grouped by
Function elements Name attribute

Sum (Duration) - Represents aggregate of the Duration attribute grouped
by Name attribute

of the immediate parent Function.It can be assumed that the Event node
will always have a

Function element as parent as per schema



TIA,

Manoj
 

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

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,165
Latest member
JavierBrak
Top