Tyagi You could use server fields - see
xdmp:set/get-server-field. ( http://docs.marklogic.com/xdmp:set-server-field ) Or you can save a map as a document ( first part of below ) and access it as per second part of below, which could be wrapped into a small utility function. let $map := map:entry("A",1) + map:entry("B",1) return xdmp:document-insert("/map.xml",document{$map}) ; map:map(fn:doc("/map.xml")/*) There won't be any disk overhead if you're accessing frequently as it will be in the expanded tree cache. Ken Tune -----Original Message----- From: [email protected] [mailto:[email protected]] On Behalf Of Tyagi, Devesh Sent: 27 July 2015 11:24 To: MarkLogic Developer Discussion Subject: Re: [MarkLogic Dev General] XQuery evaluation Thanks Florent and Geert, The real motive behind this question is to implement a globally available map for all the functions of the xquery module. Any suggestions about how to implement it? May be I can put it in a different Xquery module and import it? Regards, Devesh ________________________________________ From: [email protected] <[email protected]> on behalf of Florent Georges <[email protected]> Sent: Monday, July 27, 2015 1:55 PM To: MarkLogic Developer Discussion Subject: Re: [MarkLogic Dev General] XQuery evaluation Hi, Yet a cleaner solution would be to make the init function to return the map to assign to the global variable, so there is no hidden dependency: declare variable $global-map := my:init(); declare function my:init() { let $map := map:map() ... return $map }; If the init code is that simple, the let expression can then even be used straight in the variable value expression, without using a function. Avoiding side-effects when none is required will save you some (hard-to-track-down) troubles. Regards, -- Florent Georges http://fgeorges.org/ http://h2oconsulting.be/ On 27 July 2015 at 10:16, Geert Josten wrote: > Hi Devesh, > > XQuery specification allows lazy evaluation, and MarkLogic makes heavy > use of that. Just don't put the call to your init function in a > declare variable, but simply call it before the local:test. Something like: > > let $init := local:initialize-variables() return > local:test() > > Cheers, > Geert > > From: <[email protected]> on behalf of "Tyagi, Devesh" > <[email protected]> > Reply-To: MarkLogic Developer Discussion > <[email protected]> > Date: Monday, July 27, 2015 at 9:55 AM > To: "[email protected]" > <[email protected]> > Subject: [MarkLogic Dev General] XQuery evaluation > > Hi, > > > I have the following piece of code in XQuery: > > > declare variable $triple-predicate-prefix := > "http://www.bsi.org/predicates/"; > > declare variable $triple-predicate-suffix-hasTaxonomyName := > "hasTaxonomyName"; > > > declare variable $triple-predicates-map := map:map(); > > declare variable $initialize-variables-caller := > local:initialize-variables(); > > > declare function local:initialize-variables(){ > > let $_ := > map:put($triple-predicates-map,$triple-predicate-suffix-hasTaxonomyNam > e,fn:concat($triple-predicate-prefix,$triple-predicate-suffix-hasTaxon > omyName)) > > return () > > }; > > > declare local:test(){ > > map:get($triple-predicates-map,$triple-predicate-suffix-hasTaxonomyNam > e) > > }; > > > local:test() > > > This returns me and empty sequence. The map doesn't get initialized. > It would be helpful if someone could point me towards the reason and > solution behind it. > > > Thanks and regards, > > Devesh > > "This e-mail and any attachments transmitted with it are for the sole > use of the intended recipient(s) and may contain confidential , > proprietary or privileged information. If you are not the intended > recipient, please contact the sender by reply e-mail and destroy all > copies of the original message. Any unauthorized review, use, > disclosure, dissemination, forwarding, printing or copying of this > e-mail or any action taken in reliance on this e-mail is strictly prohibited > and may be unlawful." > > _______________________________________________ > General mailing list > [email protected] > Manage your subscription at: > http://developer.marklogic.com/mailman/listinfo/general > _______________________________________________ General mailing list [email protected] Manage your subscription at: http://developer.marklogic.com/mailman/listinfo/general "This e-mail and any attachments transmitted with it are for the sole use of the intended recipient(s) and may contain confidential , proprietary or privileged information. If you are not the intended recipient, please contact the sender by reply e-mail and destroy all copies of the original message. Any unauthorized review, use, disclosure, dissemination, forwarding, printing or copying of this e-mail or any action taken in reliance on this e-mail is strictly prohibited and may be unlawful." _______________________________________________ General mailing list [email protected] Manage your subscription at: http://developer.marklogic.com/mailman/listinfo/general _______________________________________________ General mailing list [email protected] Manage your subscription at: http://developer.marklogic.com/mailman/listinfo/general
