Hi David and Geert,

Thanks for all the suggestions. If for xdmp:eval, I send request path  
as external variable, it means somewhere I have to hardcode the path.  
I will be a problem when I move the code around to different servers.  
So even adding main module file is not good practice, for now at least  
I won't have to remember changing the path for every deployment. I'll  
keep it this way until I find a better solution.

Trying to understand more, I did some test for the xdmp:function:  I  
created a test function in my module
declare function oit:mytest() as xs:string
{
    fn:concat("hello")
};


and then from another file, I tried to call it using xdmp:apply.

import module namespace oit="http://www.aip.org/helen.xqy";
        at "/dev/newsci/helen.xqy";

  let $function := xdmp:function(xs:QName("oit:mytest"))
   return
   (
   "---apply function---",
    xdmp:apply($function),
    "--- function name---",
   xdmp:function-name( $function),
   "---module ---",
   xdmp:function-module($function)
   )


the xdmp:apply and xdmp:function-name works fine, but the  
xdmp:function-module($function) returns empty.
if I do the following
let $function := xdmp:function(xs:QName("oit:mytest"), "./helen.xqy" )
the xdmp:apply() will complain no helen.xqy found, it seems xdmp:apply  
looks from the module root for path. And in this situation  
xdmp:function-module will just return the string in param "helen.xqy",  
it does not return the full path to me, and it does not complain error.

so it  seems that xdmp:function-module cannot provide the full module  
path that I want.

and for xdmp:apply, when I define the xdmp:function, if I only provide  
xs:QName with namespace, it works fine, but if I provide the second  
param for module path using relative path, xdmp:apply failed, from  
this test it seems that xdmp:apply can only recognize the full path,  
not relative path.

So one thing I want to make sure I understand correct is: when you say  
xdmp:apply is best alternative for relative path, you mean make the  
QName for xdmp:function using in-scope context, not provide relative  
path for second param as module-path, right?


Thanks, Helen


On Jul 9, 2010, at 7:04 AM, Geert Josten wrote:

> Hi Helen, David,
>
> Import statements within eval expressions start looking for files  
> from modules-root as specified in the app server. You need xdmp:get- 
> request-path to make it work, there are currently no alternatives,  
> except passing in the request path as an external var when calling  
> the xdbc server.
>
> Xdmp:apply and xdmp:invoke are indeed the best alternatives for  
> relative paths, but the xdmp:apply doesn't make the function run in  
> a separate transaction. I personally dislike having many main  
> modules, but unless you are willing to send the request path as  
> external var yourself there are only little alternatives..
>
> Kind regards,
> Geert
>
>> -----Original Message-----
>> From: [email protected]
>> [mailto:[email protected]] On Behalf Of
>> Lee, David
>> Sent: donderdag 8 juli 2010 21:46
>> To: General Mark Logic Developer Discussion
>> Subject: Re: [MarkLogic Dev General] how to do
>> multi-transaction in afunction
>>
>> You are right, I think.
>> Inside eval it starts from scratch.
>> Maybe this can help ????
>>
>> http://developer.marklogic.com/pubs/4.1/apidocs/Ext-8.html#xdm
>> p:function
>> -module
>>
>>
>> If you can get ahold of a function thats already imported
>> maybe you can find its path and pass that to eval.
>>
>>
>>
>> -----Original Message-----
>> From: [email protected]
>> [mailto:[email protected]] On Behalf Of
>> helen chen
>> Sent: Thursday, July 08, 2010 3:19 PM
>> To: General Mark Logic Developer Discussion
>> Subject: Re: [MarkLogic Dev General] how to do
>> multi-transaction in afunction
>>
>> Hi David,
>>
>> Maybe my test was not right. I feel inside xdmp:eval, it does
>> not know the caller module's path, inside eval, the path
>> start from app server root. I'll do another test again and
>> see if I can get relative path.
>>
>> Thanks, Helen
>>
>> On Jul 8, 2010, at 2:44 PM, Lee, David wrote:
>>
>>> There's probably a way !
>>> But what I do in similar cases is use relative paths
>>>
>>> import module namespace="mine" at "../../common/module.xqy" ;
>>>
>>>
>>>
>>>
>>> -----Original Message-----
>>> From: [email protected]
>>> [mailto:[email protected]] On Behalf Of helen
>> chen
>>> Sent: Thursday, July 08, 2010 2:41 PM
>>> To: General Mark Logic Developer Discussion
>>> Subject: Re: [MarkLogic Dev General] how to do multi-transaction in
>>> afunction
>>>
>>> Hi David,
>>>
>>> our path is two part:
>>>
>>> first path is the app server root, like /data/marklogic, this one I
>> can
>>> use xdmp:modules-root(  ) to get it
>>>
>>> for second part, (this is where the marklogic path start),
>> usually we
>>> put code under newsci/helen.xqy,  but for our dev machine or test
>>> machine, we prefix the path with /dev/ or /test, so the path may be
>>> /dev/newsci/helen.xqy or /test/newsci/helen.xqy.
>>>
>>> if I use xdmp:eval, I need to create xqy string.  when I do
>> an import,
>>> it will be like import module namespace
>>> oit=""http://www.aip.org/helen.xqy";;  at
>> "/dev/newsci/helen.xqy"; but
>>> in production, it will be import module namespace
>>> oit=""http://www.aip.org/helen.xqy";;  at "/newsci/helen.xqy";
>>>
>>> I don't know how to get the path "/dev/newsci/" or just "/newsci/"
>>> dynamically, and I don't want to do any hardcode like /dev or /test.
>>>
>>>
>>> Thanks, Helen
>>>
>>>
>>> On Jul 8, 2010, at 2:20 PM, Lee, David wrote:
>>>
>>>> xdmp:get-request-path()  wont return anything for XDBC connections
>>> (only
>>>> HTTP).
>>>>
>>>> You can use :
>>>>
>>>> xdmp:modules-root(  ) as  xs:string
>>>>
>>>>
>>>
>> http://developer.marklogic.com/pubs/4.1/apidocs/Ext-7.html#xdm
>> p:modules-
>>>> root
>>>>
>>>> To get the root path for modules from XDBC
>>>>
>>>>
>>>> ----------------------------------------
>>>> David A. Lee
>>>> Senior Principal Software Engineer
>>>> Epocrates, Inc.
>>>> [email protected]
>>>> 812-482-5224
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> -----Original Message-----
>>>> From: [email protected]
>>>> [mailto:[email protected]] On Behalf Of helen
>>> chen
>>>> Sent: Wednesday, July 07, 2010 5:04 PM
>>>> To: General Mark Logic Developer Discussion
>>>> Subject: Re: [MarkLogic Dev General] how to do
>> multi-transaction in
>>>> afunction
>>>>
>>>> Hi Danny and Geert,
>>>>
>>>> I'm using xdbc server, the xdmp:get-request-path() does
>> not seem to
>>>> return value for me.  And also both of our module root path and
>> module
>>>> path can be different with prefix for different server, if I build
>> the
>>>> module path string, I have to hardcode some part of path.
>> Finally I
>>>> figured out to change xdmp:eval to be xdmp:invoke, and I
>> put the code
>>>> for eval into another file. This way the xdmp:invoke can
>> use relative
>>>> module path and I don't need to hardcode anything.
>>>>
>>>> Let me know if you see anything wrong with my idea.  Thanks for all
>>> the
>>>> help.
>>>>
>>>> Helen
>>>>
>>>>
>>>> On Jul 7, 2010, at 12:04 PM, Geert Josten wrote:
>>>>
>>>>> Hi Helen,
>>>>>
>>>>> I think you are looking for fn:resolve-uri(".",
>>>> xdmp:get-request-path())..
>>>>>
>>>>> Kind regards,
>>>>> Geert
>>>>>
>>>>>> -----Original Message-----
>>>>>> From: [email protected]
>>>>>> [mailto:[email protected]] On
>> Behalf Of helen
>>>>>> chen
>>>>>> Sent: woensdag 7 juli 2010 16:41
>>>>>> To: General Mark Logic Developer Discussion
>>>>>> Subject: Re: [MarkLogic Dev General] how to do
>> multi-transaction in
>>>>>> afunction
>>>>>>
>>>>>> Hi Danny and Geert,
>>>>>>
>>>>>>
>>>>>> Thanks for all the helping. I almost made it work. The
>> only thing I
>>>>>> have here is: when I do the eval, I need to call a function in a
>>>>>> module. The module file is really the same file that I'm
>> building
>>>>>> the xdmp:eval query, but I couldn't make eval know the
>> current path
>>>>>> this module is, so I have to specify the full path.
>>>>>> For example, I have module file at the path
>> /dev/newsci/helen.xqy ,
>>>>>> and then you can see I put full path import module namespace
>>>>>> oit=""http://www.aip.org/helen.xqy";;  at
>> "/dev/newsci/helen.xqy";
>>>>>> in my xdmp:eval, this is going to be a problem because the app
>>>>>> server's path on our production server will be different.
>>>>>>
>>>>>> Does anyone know how I can make the path dynamic? or how
>> to avoid
>>>>>> this problem?
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>> my code piece is like the following:
>>>>>>
>>>>>>
>>>>>> xquery version "1.0-ml";
>>>>>>
>>>>>>
>>>>>> module namespace oit = "http://www.aip.org/helen.xqy";;
>>>>>>
>>>>>>
>>>>>> declare function oit:mytest()
>>>>>> {
>>>>>> let $c1 := "http://py";
>>>>>> let $c2 := "http://mytest";
>>>>>> let $cvi := <cvi>
>>>>>>                 <coden>ABC</coden>
>>>>>>                 <volume>90</volume>
>>>>>>                 <issue>1</issue>
>>>>>>             </cvi>
>>>>>> let $oi-state := "PROD"
>>>>>> return
>>>>>> (
>>>>>> xdmp:eval('xdmp:document-insert("/aa.xml", <foo/>)') ,
>>>>>> xdmp:eval('xquery version "1.0-ml";
>>>>>>        declare variable $e1 as xs:string external;
>>>>>>        declare variable $e2 as xs:string  external;
>>>>>>        xdmp:document-set-collections( "/aa.xml", ($e1))
>>>>>>        ,
>>>>>>        xdmp:document-get-collections("/aa.xml")
>>>>>>        ,
>>>>>>        xdmp:document-add-collections( "/aa.xml", ($e2))'
>>>>>>       ,
>>>>>>       (xs:QName("e1"), $c1, xs:QName("e2"), $c2)
>>>>>>
>>>>>>      )
>>>>>> ,
>>>>>> xdmp:eval( 'xquery version "1.0-ml";
>>>>>>                import module namespace
>>>>>> oit=""http://www.aip.org/helen.xqy";;  at "/dev/newsci/helen.xqy";
>>>>>>                declare variable $cvi as  element(cvi) external;
>>>>>>                declare variable $state as xs:string  external;
>>>>>>
>>>>>> oit:create-online-issue-table($cvi/coden/text(),
>>>>>> $cvi/volume/text(), $cvi/issue/text(), $state)'
>>>>>>                ,
>>>>>>                (xs:QName("cvi"), $cvi, xs:QName("state"),
>>>>>> $oi-state)
>>>>>>             )
>>>>>>
>>>>>>
>>>>>> )
>>>>>> };
>>>>>>
>>>>>> then I call
>>>>>>
>>>>>>
>>>>>> oit:mytest()
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>> On Jul 7, 2010, at 2:42 AM, Geert Josten wrote:
>>>>>>
>>>>>>
>>>>>> Hi Helen,
>>>>>>
>>>>>> It is a subtle typo. It sometimes helps to take the query from
>>>>>> inside the eval, and test it all by itself in CQ.
>>>>>> If you do so, you see the same 'unexpected token' message as you
>>>>>> would get when it is inside the eval, but you get a
>> better focus on
>>>>>> which line it concerns. In this case it concerns your external
>>>>>> variable declarations. There should be no 'as' before
>> the external
>>>>>> keyword..
>>>>>>
>>>>>> Kind regards,
>>>>>> Geert
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>> drs. G.P.H. (Geert) Josten
>>>>>> Consultant
>>>>>>
>>>>>> Daidalos BV
>>>>>> Hoekeindsehof 1-4
>>>>>> 2665 JZ Bleiswijk
>>>>>>
>>>>>> T +31 (0)10 850 1200
>>>>>> F +31 (0)10 850 1199
>>>>>>
>>>>>> mailto:[email protected]
>>>>>> http://www.daidalos.nl/
>>>>>>
>>>>>> KvK 27164984
>>>>>>
>>>>>>
>>>>>> De informatie - verzonden in of met dit e-mailbericht - is
>>>>>> afkomstig van Daidalos BV en is uitsluitend bestemd voor de
>>>>>> geadresseerde. Indien u dit bericht onbedoeld hebt ontvangen,
>>>>>> verzoeken wij u het te verwijderen. Aan dit bericht kunnen geen
>>>>>> rechten worden ontleend.
>>>>>>
>>>>>>
>>>>>>
>>>>>>         From: [email protected]
>>>>>>
>>>>>>
>>>>>>
>>>>>> [mailto:[email protected]] On Behalf Of
>>>>>>
>>>>>>
>>>>>>         Helen Chen
>>>>>>
>>>>>>
>>>>>>         Sent: woensdag 7 juli 2010 4:03
>>>>>>
>>>>>>
>>>>>>         To: General Mark Logic Developer Discussion
>>>>>>
>>>>>>
>>>>>>         Subject: Re: [MarkLogic Dev General] how to do
>>>>>>
>>>>>>
>>>>>>         multi-transaction in a function
>>>>>>
>>>>>>
>>>>>>
>>>>>>         Hi Danny,
>>>>>>
>>>>>>
>>>>>>
>>>>>>         it works with plain query. usually in my
>> function I have some
>>>>>>
>>>>>>
>>>>>>         variables and I need to use these variables for
>>>>>> eval. I tried
>>>>>>
>>>>>>
>>>>>>         the following and I couldn't make it work. Can
>>>>>> you help me?
>>>>>>
>>>>>>
>>>>>>
>>>>>>         xquery version "1.0-ml";
>>>>>>
>>>>>>
>>>>>>
>>>>>>         declare function local:mytest()
>>>>>>
>>>>>>
>>>>>>         {
>>>>>>
>>>>>>
>>>>>>         let $c1 := "http://py";
>>>>>>
>>>>>>
>>>>>>         let $c2 := "http://mytest";
>>>>>>
>>>>>>
>>>>>>         return
>>>>>>
>>>>>>
>>>>>>         (
>>>>>>
>>>>>>
>>>>>>         xdmp:eval('xdmp:document-insert("/aa.xml", <foo/>)') ,
>>>>>>
>>>>>>
>>>>>>         xdmp:eval('xquery version "1.0-ml";
>>>>>>
>>>>>>
>>>>>>                   declare variable $e1 as external;
>>>>>>
>>>>>>
>>>>>>                   declare variable $e2 as external;
>>>>>>
>>>>>>
>>>>>>                   xdmp:document-set-collections(
>>>>>> "/aa.xml", ($e1))
>>>>>>
>>>>>>
>>>>>>                   ,
>>>>>>
>>>>>>
>>>>>>                   xdmp:document-get-collections("/aa.xml")
>>>>>>
>>>>>>
>>>>>>                   ,
>>>>>>
>>>>>>
>>>>>>                   xdmp:document-add-collections(
>>>>>> "/aa.xml", ($e2))'
>>>>>>
>>>>>>
>>>>>>                  ,
>>>>>>
>>>>>>
>>>>>>                  (xs:QName("e1"), $c1, xs:QName("e2"), $c2)
>>>>>>
>>>>>>
>>>>>>
>>>>>>                 )
>>>>>>
>>>>>>
>>>>>>         ,
>>>>>>
>>>>>>
>>>>>>         xdmp:eval('xdmp:document-get-collections("/aa.xml")')
>>>>>>
>>>>>>
>>>>>>         )
>>>>>>
>>>>>>
>>>>>>         };
>>>>>>
>>>>>>
>>>>>>
>>>>>>         local:mytest()
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>         On Jul 6, 2010, at 5:18 PM, Danny Sokolsky wrote:
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>              You need to make the updates happen in a separate
>>>>>>
>>>>>>
>>>>>>         transaction and then make the get-collections
>>>>>> happen in a
>>>>>>
>>>>>>
>>>>>>         separate transaction that has a timestamp later than the
>>>>>>
>>>>>>
>>>>>>         update.  One way to do that is by making them
>>>>>> each do evals.
>>>>>>
>>>>>>
>>>>>>         SOmething like:
>>>>>>
>>>>>>
>>>>>>
>>>>>>              xquery version "1.0-ml";
>>>>>>
>>>>>>
>>>>>>              declare function local:mytest()
>>>>>>
>>>>>>
>>>>>>              {
>>>>>>
>>>>>>
>>>>>>              (
>>>>>>
>>>>>>
>>>>>>              xdmp:eval('xdmp:document-insert("/aa.xml",
>>>>>> <foo/>)'),
>>>>>>
>>>>>>
>>>>>>              xdmp:eval('xdmp:document-set-collections(
>>>>>> "/aa.xml",
>>>>>>
>>>>>>
>>>>>>         ("http://py";))
>>>>>>
>>>>>>
>>>>>>              ,
>>>>>>
>>>>>>
>>>>>>              xdmp:document-get-collections("/aa.xml")
>>>>>>
>>>>>>
>>>>>>              ,
>>>>>>
>>>>>>
>>>>>>              xdmp:document-add-collections( "/aa.xml",
>>>>>> ("http://mytest";))')
>>>>>>
>>>>>>
>>>>>>              ,
>>>>>>
>>>>>>
>>>>>>
>>>>>> xdmp:eval('xdmp:document-get-collections("/aa.xml")')
>>>>>>
>>>>>>
>>>>>>              )
>>>>>>
>>>>>>
>>>>>>              };
>>>>>>
>>>>>>
>>>>>>
>>>>>>              local:mytest()
>>>>>>
>>>>>>
>>>>>>
>>>>>>              -Danny
>>>>>>
>>>>>>
>>>>>>
>>>>>>              From: [email protected]
>>>>>>
>>>>>>
>>>>>>
>>>>>> [mailto:[email protected]] On Behalf Of
>>>>>>
>>>>>>
>>>>>>         helen chen
>>>>>>
>>>>>>
>>>>>>              Sent: Tuesday, July 06, 2010 2:03 PM
>>>>>>
>>>>>>
>>>>>>              To: General Mark Logic Developer Discussion
>>>>>>
>>>>>>
>>>>>>              Subject: [MarkLogic Dev General] how to do
>>>>>>
>>>>>>
>>>>>>         multi-transaction in a function
>>>>>>
>>>>>>
>>>>>>
>>>>>>              I want to do an update to a document and
>>>>>> then see the
>>>>>>
>>>>>>
>>>>>>         update immediately. I did a test like the following:
>>>>>>
>>>>>>
>>>>>>              I add a collection to a document, then try
>>>>>> to get it,
>>>>>>
>>>>>>
>>>>>>         within the same transaction I cannot see the
>>>>>> new collection.
>>>>>>
>>>>>>
>>>>>>         That means I have to be in the seperate transaction.
>>>>>>
>>>>>>
>>>>>>
>>>>>>              declare function local:mytest()
>>>>>>
>>>>>>
>>>>>>              {
>>>>>>
>>>>>>
>>>>>>              (
>>>>>>
>>>>>>
>>>>>>              xdmp:document-set-collections( "/aa.xml",
>>>>>> ("http://py";))
>>>>>>
>>>>>>
>>>>>>              ,
>>>>>>
>>>>>>
>>>>>>              xdmp:document-get-collections("/aa.xml")
>>>>>>
>>>>>>
>>>>>>              ,
>>>>>>
>>>>>>
>>>>>>              xdmp:document-add-collections( "/aa.xml",
>>>>>> ("http://mytest";))
>>>>>>
>>>>>>
>>>>>>              ,
>>>>>>
>>>>>>
>>>>>>              xdmp:document-get-collections("/aa.xml")
>>>>>>
>>>>>>
>>>>>>              )
>>>>>>
>>>>>>
>>>>>>              };
>>>>>>
>>>>>>
>>>>>>
>>>>>>              local:mytest()
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>              How can I make the last line
>>>>>>
>>>>>>
>>>>>>         xdmp:document-get-collections("/aa.xml") as seperate
>>>>>>
>>>>>>
>>>>>>         transaction so I can see the change?
>>>>>>
>>>>>>
>>>>>>
>>>>>>              Thanks, Helen
>>>>>>
>>>>>>
>>>>>>              _______________________________________________
>>>>>>
>>>>>>
>>>>>>              General mailing list
>>>>>>
>>>>>>
>>>>>>              [email protected]
>>>>>>
>>>>>>
>>>>>>
>>>>>> http://developer.marklogic.com/mailman/listinfo/general
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>> _______________________________________________
>>>>>> General mailing list
>>>>>> [email protected]
>>>>>> http://developer.marklogic.com/mailman/listinfo/general
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>> _______________________________________________
>>>>> General mailing list
>>>>> [email protected]
>>>>> http://developer.marklogic.com/mailman/listinfo/general
>>>>
>>>> _______________________________________________
>>>> General mailing list
>>>> [email protected]
>>>> http://developer.marklogic.com/mailman/listinfo/general
>>>> _______________________________________________
>>>> General mailing list
>>>> [email protected]
>>>> http://developer.marklogic.com/mailman/listinfo/general
>>>
>>> _______________________________________________
>>> General mailing list
>>> [email protected]
>>> http://developer.marklogic.com/mailman/listinfo/general
>>> _______________________________________________
>>> General mailing list
>>> [email protected]
>>> http://developer.marklogic.com/mailman/listinfo/general
>>
>> _______________________________________________
>> General mailing list
>> [email protected]
>> http://developer.marklogic.com/mailman/listinfo/general
>> _______________________________________________
>> General mailing list
>> [email protected]
>> http://developer.marklogic.com/mailman/listinfo/general
>>
> _______________________________________________
> 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