[xquery-talk] Adding content for with distinct-values

Michael Kay mhk at mhk.me.uk
Thu Dec 9 22:32:53 PST 2004


I suspect that grouping with XQuery is going to turn into as arcane an art
as grouping in XSLT 1.0, with the difference that there's no key() function
to assist. (And that some implementations of XQuery might not support the
preceding-sibling axis).

The simplest solution is probably

for $d in distinct-values(dy:iu-count/@ID)
return <dy:iu-count ID="{$d}"> {
   sum( dy at iu-count[@ID=$d] )
} </dy:iu-count>

Note that distinct-values returns the results in undefined order.

Michael Kay
http://www.saxonica.com/ 

> -----Original Message-----
> From: talk-bounces at xquery.com 
> [mailto:talk-bounces at xquery.com] On Behalf Of Bruno Chatel
> Sent: 09 December 2004 21:36
> To: talk at xquery.com
> Subject: [xquery-talk] Adding content for with distinct-values
> 
> Hi,
> 
> I am looking for a way to do the following (and do not find)..
> 
> I have a node set containing something like
>  
> <dy:iu-count ID ="n0001000300040011|000100010002" > 1 </ 
> dy:iu-count > 
> <dy:iu-count ID ="n0001000300040011|000100010002" > 1 </ 
> dy:iu-count > 
> <dy:iu-count ID ="n00010002001100030002|000100020003" > 1 </ 
> dy:iu-count > 
> <dy:iu-count ID ="n0001000500040004|000100080004" > 1 </ 
> dy:iu-count > 
> <dy:iu-count ID ="n0001000500040004|000100080004" > 1 </ 
> dy:iu-count > 
> <dy:iu-count ID ="n0001000500040004|000100080004" > 1 </ 
> dy:iu-count > 
> <dy:iu-count ID ="n0001000500040004|000100080004" > 1 </ 
> dy:iu-count > 
> 
> and i like to return this :
> 
> <dy:iu-count ID ="n0001000300040011|000100010002" > 2 </ 
> dy:iu-count > 
> <dy:iu-count ID ="n00010002001100030002|000100020003" > 1 </ 
> dy:iu-count > 
> <dy:iu-count ID ="n0001000500040004|000100080004" > 4 </ 
> dy:iu-count > 
> 
> I suspect using distinct-values and sum but do not succeed.
> 
> Thanks in advance for your help
> 
> Regards
> 
> -- bruno -- 
> Bruno Chatel
> Tel : (+33) (0)4 96 11 14 57
> bcha at chadocs.com
> --------------------------------------
> 
> 
> _______________________________________________
> talk at xquery.com
> http://xquery.com/mailman/listinfo/talk
> 



More information about the talk mailing list