[MarkLogic Dev General] Best way to search collection from Stored XQuery

Evan Lenz Evan.Lenz at marklogic.com
Mon Oct 10 09:36:43 PDT 2011


Hi Betty,

I'm not sure, but I'm guessing it's a 1.0 vs. 1.0-ml issue.

Try adding collection() before the "//c" in your first example, since
that's probably what you're intending. The implicit addition of
"collection()" when a context node isn't defined is specific to MarkLogic.
On the other hand, when a context node is defined, it starts from the
document node of the same document as the context node, not the entire
collection.

Your second example shouldn't work because you're trying to use a path
expression on a simple value ($a).

Evan Lenz
Software Developer, Community
MarkLogic Corporation
http://developer.marklogic.com



On 10/10/11 8:52 AM, "Betty Harvey" <harvey at eccnet.com> wrote:

>The following works perfectly in CQ:
>
>for $a in distinct-values(//a/b)
>let $c := //c[d = $a]/descendant::era:e
>order by $a
>return
><tr>
><td>{$a}</td>
><td>{$c}/></td>
></tr>
>
>The same query in stored XQuery gives an error "Expression depends on the
>context where none is defined".
>
>I have tried multiple XPath approaches but I haven't been able to get the
>XPath statement to move above the currently document in the collection:
>
>for $a in distinct-values(collection()/a/b)
>let $c := $a/ancestor::a/../descendant::c[d = $a]/descendant::era:e
>order by $a
>return
><tr>
><td>{$a}</td>
><td>{$c}/></td>
></tr>
>
>What is the best approach for doing joins within MarkLogic within a
>collection?  It is probably something really simple that I am not finding.
>
>TIA!
>
>Betty
>
>/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/
>Betty Harvey                         | Phone:  410-787-9200  FAX: 9830
>Electronic Commerce Connection, Inc. |
>harvey at eccnet.com                    | Washington,DC XML Users Grp URL:
>http://www.eccnet.com          | http://www.eccnet.com/xmlug
>/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\\/\/
>Member of XML Guild (www.xmlguild.org)
>
>
>
>_______________________________________________
>General mailing list
>General at developer.marklogic.com
>http://developer.marklogic.com/mailman/listinfo/general



More information about the General mailing list