[xquery-talk] Get the context item form function
Andrew Welch
andrew.j.welch at gmail.com
Tue Aug 16 03:59:00 PDT 2011
> I have a simple XQuery declaring a function. The declared function is called
> from the body without any parameters as follows:
>
> -- start snippet --
> declare function local:main() as element()*{
> let $items := //item
> return $items
> };
>
> <result>{
> local:main()
> }</result>
> result ist: XPDY0002: The context item is undefined at this point
> The exception is thrown when the expression is loaded
You have to pass the context to the function as a parameter....
> declare variable $somedoc as document-node() external;
or change that to:
declare variable $somedoc as document-node() := doc('foo.xml');
so the query pulls in the xml itself, but it's still a good idea pass
$somedoc to the function rather just reference the global from within
the function.
--
Andrew Welch
http://andrewjwelch.com
More information about the talk
mailing list