In MarkLogic, the default context is all of the documents in the database to 
which your App Server is configured.  So fn:collection() is equivalent to the 
default context.

-Danny

-----Original Message-----
From: [email protected] 
[mailto:[email protected]] On Behalf Of G. Ken Holman
Sent: Wednesday, February 09, 2011 1:28 PM
To: General MarkLogic Developer Discussion
Subject: Re: [MarkLogic Dev General] using XPath with no context

At 2011-02-09 14:21 -0700, [email protected] wrote:
>What are the implications of doing:
>
>/article

That is valid only if the processor gives you a source node tree at 
invocation time.

>vs
>
>fn:collection()/article

fn:collection() returns document nodes, so there is no "missing context".

>or
>
>fn:doc()/article

fn:doc() returns a document node, so there is no "missing context".


>?
>
>Seems like the first one shouldn't be allowed since no context is 
>specified, yet it seems to work. Is that part of the XQuery spec or 
>is that part of the 1.0-ml dialect? (seems so because when I specify 
>1.0 I get an error). What is happening behind the scenes when no 
>context is specified?

All depends on the processor.  Saxon is an XQuery processor that 
accepts a source document specification on the command line and so 
"/article" is in the context of the document node of that source 
document.  If you run Saxon without supplying a source document, you 
get an error.

A processor defines what is in the dynamic context at the time 
document processing starts:

   http://www.w3.org/TR/2007/REC-xquery-20070123/#eval_context

Looking at the list of components here:

   
http://www.w3.org/TR/2007/REC-xquery-20070123/#id-xq-evaluation-context-components

... you can see that the current node, and therefore the tree of the 
current node, can be overwritten by the implementation.

With Saxon, that current node and tree depends on the presence of the 
command line argument.

I cannot quickly find the MarkLogic documentation of the value of the 
current node in the dynamic context at the start of 
processing.  Perhaps someone else can post this.

> From a stach trace it looks like fn:collection() is inserted behind 
> the scenes. If so, what's the thinking for that doing that?

The static context defines what fn:collection() returns:

    http://www.w3.org/TR/2007/REC-xquery-20070123/#static_context
    
http://www.w3.org/TR/2007/REC-xquery-20070123/#id-xq-static-context-components
    "Statically-known collections" - augmentable

And so, again, it is up to the processor to define this.  I believe 
MarkLogic returns the set of document nodes of every document.

>Also, it looks like this is a way to be able to write somewhat 
>dynamic XQuery by doing something like this:
>
>let $query := /article/title
>
>return fn:collection()/$query
>
>Which apparently is the equivalent of fn:collection()//article/title

That is not valid XPath 2.0 or XQuery 1.0 syntax.

I hope this helps.

. . . . . . . . .  Ken

--
Contact us for world-wide XML consulting & instructor-led training
Crane Softwrights Ltd.          http://www.CraneSoftwrights.com/q/
G. Ken Holman                 mailto:[email protected]
Legal business disclaimers:  http://www.CraneSoftwrights.com/legal

_______________________________________________
General mailing list
[email protected]
http://developer.marklogic.com/mailman/listinfo/general
_______________________________________________
General mailing list
[email protected]
http://developer.marklogic.com/mailman/listinfo/general

Reply via email to