Hi Mark,

Look closely at the code that is throwing this message.  Usually it means that 
it is trying to evaluate an expression as an XPath expression, but there is no 
context item (such as a /).  And most of the time (at least for me) this 
happens due to a syntax error/typo.

For example, the following XQuery throws that error:

hello

But the following does not:

/hello

-Danny

From: [email protected] 
[mailto:[email protected]] On Behalf Of Mark Boyd
Sent: Thursday, February 04, 2010 3:43 PM
To: General Mark Logic Developer Discussion
Subject: [MarkLogic Dev General] context item within function calls

How do functions like fn:root and fn:string-length get access to the "context 
item" of the calling xquery code? For example, knowing that where the following 
function is called my context item will always have an attribute of "product" 
with a comma separated list of products to which the assembly applies, how can 
I write my functions like fn:root such that the parameter is optional and the 
context item is the default? Example:

declare function is-part-of(
 $assembly as xs:string?  <--- note optionality (sic) of this parameter
) as xs:boolean {
 if ($product)
  then fn:contains($assembly/@product, $product)
 else fn:contains(./@product, $product)  <--- note use of context node "."
};

This results in:

[1.0-ml] XDMP-CONTEXT: (err:XPDY0002) Expression depends on the context where 
none is defined

But,

$assembly/@product[fn:string-length() > 10]

compiles and runs just fine. So how is this implemented?

Mark

Mark R. Boyd
Principle Engineer
ICS Department
The Church of Jesus Christ of Latter-Day Saints



NOTICE: This email message is for the sole use of the intended recipient(s) and 
may contain confidential and privileged information. Any unauthorized review, 
use, disclosure or distribution is prohibited. If you are not the intended 
recipient, please contact the sender by reply email and destroy all copies of 
the original message.

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

Reply via email to