[xquery-talk] A walk down Sesame St - counting for simpletons

Michael Sokolov msokolov at safaribooksonline.com
Tue Apr 8 08:46:46 PDT 2014


On 04/08/2014 11:23 AM, Ihe Onwuka wrote:
> count(colllection('myColl')//elem tells me how many elems there are in
> myColl. Fine
>
> So now I want to be told how many elems are in myColl and myColl2.
>
> Put them in a sequence like so
>
> (collection('myColl')//elem,collection('myColl2')//elem) and then
> apply the count method to each element of the sequence n'est pas?
>
> (collection('myColl')//elem,collection('myColl2')//elem)/count(.)
>
> 2 collections to give me 2 numbers .C'est domage, Mais non. That only
> gives me one number - the count of elems in MyColl.
That should give you the total count of both.  You are thinking that you 
have a sequence of sequences, but you don't since there is no such thing 
in XPath -- only sequences of items (nodes and atomic values).
>
> C'est fait rien methinks (or perhaps doesn't think). 3.0 map operator
> to the rescue - let's substitute the / for a !.
>
> Sacre bleu
>
> I now have a stream of N 1's where N is the number of elems in
> MyColl............
>
> I have gone back to the more prosaic method of counting each
> collection with a comma separator to transform the answer to a
> sequence.
> _______________________________________________
> talk at x-query.com
> http://x-query.com/mailman/listinfo/talk



More information about the talk mailing list