This has to be looked at the light of history. While defining function definitions in XQuery, it was decided to not pass the focus through function calls. I was not there so you need other sources for the exact reasons, but this is about independent expression compilation and optimization opportunities.
But XQuery 1.0 was defined as a super-set of XPath 2.0, and they share the same standard function library. XPath 1.0 allowed to implicitly reference the context node for some functions (like the name function). For compatibility purpose, those functions continued to be available in both forms: with explicit and implicit context node param. But this is only syntax sugar, that users cannot achieve in their own user functions. Regards, -- Florent Georges http://www.fgeorges.org ________________________________ De : Mark Boyd <[email protected]> À : General Mark Logic Developer Discussion <[email protected]> Envoyé le : Ven 5 Février 2010, 1 h 24 min 08 s Objet : RE: [MarkLogic Dev General] context item within function calls Yes, I understand that, currently, custom functions must pass in the context according to spec. That is inconsistent. If standard library functions can achieving it should not custom functions be allowed to do the same? Mark From:[email protected] [mailto:[email protected]] On Behalf Of Florent Georges Sent: Thursday, February 04, 2010 4:58 PM To: General Mark Logic Developer Discussion Subject: Re: [MarkLogic Dev General] context item within function calls Hi, A user function cannot access the context node. You have to pass it explicitly. Some functions in the standard library have this special power though. Regards, -- Florent Georges http://www.fgeorges.org/ ________________________________ De :Mark Boyd <[email protected]> À : General Mark Logic Developer Discussion <[email protected]> Envoyé le : Ven 5 Février 2010, 0 h 42 min 57 s Objet : [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
