[xquery-talk] some ... satisfies with positional variable

Benedikt Linse linse at cip.ifi.lmu.de
Sat Aug 20 01:15:31 PDT 2005


> Is this what you are looking for?
>
> if (exists(child::tag0[position() > 3]))
> then return $fs:dot
> else ()

Thanks for the quick reply. It comes close to what I am looking for. Just
that I would like to bind the node that satisfies the condition
"position()>3" and its position to variables in order to use them in other
nested constraints. For example

let $x := doc("foo.xml")/bar return
    if (some $y at $pos1 in $x/child::* satisfies(
          (fn:node-name($y) == "tag0") and
          (some $z at $pos2 in $x/child::* satisfies(
             (fn:node-name($x) == "tag1") and ($pos1 > $pos2))))
    then return $x else ()

This is how I would write my query if there was a
"some ... at ... in ... satisfies ..." construct. Without it, I have to
use for-clauses, which compute all tuples ($x, $y, $z) that satisfy the
conditions, although I am only interested in whether there is one such
tuple.

Benedikt

>
>                                                 -- Andrew
>
> --------------------
> Andrew Eisenberg
> IBM
> 4 Technology Park Drive
> Westford, MA  01886
>
> andrew.eisenberg at us.ibm.com
> Phone: 978-399-5158    Fax: 978-399-7012
>
>
>
>
>
> "Benedikt Linse" <linse at cip.ifi.lmu.de>
> Sent by: talk-bounces at xquery.com
> 08/19/2005 03:21 PM
>
> To
> talk at xquery.com
> cc
>
> Subject
> [xquery-talk] some ... satisfies with positional variable
>
>
>
>
>
>
> Hello,
>
> Here's a question about an XQuery language construct I would appreciate.
>
> in for-clauses it is possible to include a positional variable and return
> the context node $fs:dot - or any other node - based on the position of
> its child elements.
>
> for $x at $pos in child::tag0 return
>     if ($pos > 3) then return $fs:dot
>
> If the context node has more than 4 children, the above expression will
> return it more than once. This could be avoided by wrapping the result in
> a distinct-doc-order function, but it wouldn't prevent the compiler from
> executing extra work, does it?
>
> Without positional variables extra work can be evaded by using the some
> ... satisfies ... clause:
>
> if (some $x in child::* satisfies (fn:node-name($x) == "tag2")))
> then $fs:dot
> else ()
>
> This works fine, but I cannot include a positional variable in the
> conditional. What I need is a "some ... at ... in ... satisfies ... "
> construct similar to the following:
>
> epxr1 =
>
> if (some $x at $pos in child::* satisfies ($pos > 3))
> then $fs:dot
> else ()
>
> But this is not provided by XQuery. XPath expressions won't help since
> they're normalized to for, if-clauses, etc.
>
> Is there a special reason why a "some ... at ... in ... satisfies ..."
> construct is not provided by XQuery?
>
> Is there any possibility to express expr1 in a way that no duplicate
> elements are returned?
>
> Best regards,
>
> Benedikt
>
>
>
> _______________________________________________
> talk at xquery.com
> http://xquery.com/mailman/listinfo/talk
>
>




More information about the talk mailing list