|
[XQuery Talk Mailing List Archive Home] [By Date] [By Thread] [By Subject] [By Author] [Recent Entries] [Reply To This Message] distinct-values in Where ClausesAndrew Welch andrew.j.welch at gmail.comFri Jan 18 10:33:41 PST 2008
On 18/01/2008, Ronald Bourret <http://x-query.com/mailman/listinfo/talk> wrote:
> I'm not entirely sure what it is you want, but I have a few comments:
>
> 1) Why are you using nested for loops? The following clause:
>
> for $find in doc("resume.xml")//div, $head in $find/head, $desc in
> $find/p
> do something
>
> is similar to:
>
> for i=1 to 10
> for j=1 to 20
> for k=1 to 30
> do something
>
> That is, the code finds each div. For each div, it finds all the head
> children. And for each head child, it finds all the p children. It then
> executes the return clause once for each p child.
Just to add to that description - it's called the Cartesian product
and generates all possible combinations of the input values, eg:
for $a in 1 to 2, $b in ('a', 'b')
return concat($a, $b)
generates:
1a 1b 2a 2b
It might be easier to visualise when its two simple sequences like
that. Generally I don't think you want to use a Cartesian product
unless you know what you're doing... Maybe a seasoned xquery'er can
provide a couple of common use cases where a Cartesian product is the
ideal solution?
cheers
--
Andrew Welch
http://andrewjwelch.com
Kernow: http://kernowforsaxon.sf.net/
|
Purchase Stylus Studio Online Today!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|






