- From: Michael Dyck <MichaelDyck@home.com>
- Date: Sat, 21 Jul 2001 12:07:51 -0700
- To: mmstefan <mmstefan@mediaone.net>
- CC: Michael Good <good@recordare.com>, www-ql@w3.org
mmstefan wrote: > > I'll pitch in with my variants: > > 1. > for $p in //part > where contains(string($p/note), "CDEC") > return $p/note In the example documents, each <note> is a child of a <measure>, which is the child of a <part>. Thus, if $p is a <part>, $p/note will not select anything. Probably you meant $p//note. > This query assumes that string() takes a sequence of elements. That's not a big assumption, since it already does in XPath 1.0. (Specifically, it takes an `object' argument, which can be a nodeset.) The big assumption is what it *does* with a sequence of elements. In XPath 1.0, it would return the string-value of only one of the elements, the first in doc order. In XQuery, it's possible that it will return a sequence consisting of the string-value of each element. In your query, you appear to be assuming that it will return a concatenation of those string-values, which I suspect is unlikely. On the other hand, you could easily insert a concatSeq() function that did the job. More seriously, there's no connection between the <note>s that match "CDEC" and the <note>s that are returned. The query will return *all* <note>s of each <part> that contains one or more matches. > If [string() doesn't take a sequence of elements], just construct > a dummy element, as in: > > for $p in //part > let $foo := <foo>{$p/note}</foo> > where contains(string($foo), "CDEC") > return $foo/* ($p/part -> $p//part again.) This nicely avoids the current uncertainty of what string() will do with a sequence of elements. However, it still has the problem of returning *all* notes of each part with a match. > 2. for $p in //part > let $z := (<note>C</note>,<note>D</note>,<note>E</note>,<note>C</note>) > where subseq($z, $p/note) > return $p/note > > assuming there is a boolean function subseq() testing inclusion of a > sequence in another sequence, based on string value comparison. ($p/part -> $p//part again.) This query also has the problem of returning all notes of each part with a match. -Michael Dyck
Received on Saturday, 21 July 2001 15:13:29 UTC