Hi, Danny:

Good that you puzzled it out.

In case anyone is curious about the details, the solution would be similar to:

    let $uri := "/some/text.xml"
    return  (
        xdmp:invoke-function(function () {
            xdmp:node-replace(doc($uri)/some/path/text(), text{'replacement'})
        },
        <options xmlns="xdmp:eval">
              <transaction-mode>update-auto-commit</transaction-mode>
            </options>
        ),

        xdmp:invoke-function(function () {
            doc($uri)
        })
    )


Erik Hennum

________________________________
From: [email protected] 
[[email protected]] on behalf of Danny Sinang 
[[email protected]]
Sent: Friday, July 17, 2015 2:02 PM
To: MarkLogic Developer Discussion
Subject: Re: [MarkLogic Dev General] Displaying document after an update

Never mind ... figured it out.

The app was hanging because I had a query to the same document just before the 
xdmp:invoke-function which updates the same document.

I've now placed that initial query inside xdmp:invoke-function as well.

On Fri, Jul 17, 2015 at 4:16 PM, Danny Sinang 
<[email protected]<mailto:[email protected]>> wrote:
Hi Erik,

I got this error when I ran the code below :

XDMP-UPEXTNODES: 
xdmp:node-replace(fn:doc("/release-tracking/components/2.xml")/component/environments/environment[2],
 
<environment><name>QA</name><version>9</version><version-date>2015-07-17T16:0...</environment>)
 -- Cannot update external nodes


                        xdmp:invoke-function (
                            function () {
                                xdmp:node-replace($environment, 
$new-environment)
                            },
                            <options xmlns="xdmp:eval">
                                
<transaction-mode>update-auto-commit</transaction-mode>
                            </options>
                        )


So I did this instead :

                        xdmp:invoke-function (
                            function () {
                               let $component := fn:doc ($component-uri)/node()
                               let $environment := 
$component/environments/environment[name eq $environment-name]
                               let $new-environment :=  element environment {
                                                            for $elem in 
$environment/child::*
                                                            return
                                                               switch 
($elem/name())
                                                                    case 
"version" return <version>{$new-version-number}</version>
                                                                    case 
"version-date" return <version-date>{fn:current-dateTime()}</version-date>
                                                                    default 
return $elem
                                                        }
                                return
                                        xdmp:node-replace($environment, 
$new-environment)
                             },
                            <options xmlns="xdmp:eval">
                                
<transaction-mode>update-auto-commit</transaction-mode>
                            </options>
                        )


but the app just hung.

If I go with the code below (which uses xdmp:spawn-function), the node-replace 
works, but the document displayed is the one before the update was applied.

                       let $_ :=
                                xdmp:spawn-function (
                                    function () {
                                       let $component := fn:doc 
($component-uri)/node()
                                       let $environment := 
$component/environments/environment[name eq $environment-name]
                                       let $new-environment :=  element 
environment {
                                                                    for $elem 
in $environment/child::*
                                                                    return
                                                                       switch 
($elem/name())
                                                                            
case "version" return <version>{$new-version-number}</version>
                                                                            
case "version-date" return <version-date>{fn:current-dateTime()}</version-date>
                                                                            
default return $elem
                                                                }
                                        return
                                                xdmp:node-replace($environment, 
$new-environment)
                                     },
                                    <options xmlns="xdmp:eval">
                                        
<transaction-mode>update-auto-commit</transaction-mode>

<result>{fn:true()}</result>

                                    </options>
                                )
                          return
                                xdmp:invoke-function (
                                    function () {
                                        fn:doc($component-uri)
                                    }
                                )

Of course, this is likely due to xdmp-spawn-function running off the Task 
Server, not the current app server.

But then, how do I get xdmp:invoke-function to work ?

Regards,
Danny

On Fri, Jul 17, 2015 at 2:12 PM, Erik Hennum 
<[email protected]<mailto:[email protected]>> wrote:
Hi, Danny:

One technique is to execute xdmp:eval(), xdmp:invoke(), or 
xdmp:invoke-function() in separate transactions to write and read the result.

The main routine is the choreographer for the write and read requests and can 
keep program state.

Using inline functions and closures, xdmp:invoke-function() is especially 
convenient.


Hoping that helps,


Erik Hennum

________________________________
From: 
[email protected]<mailto:[email protected]>
 
[[email protected]<mailto:[email protected]>]
 on behalf of Danny Sinang [[email protected]<mailto:[email protected]>]
Sent: Friday, July 17, 2015 10:51 AM
To: general
Subject: [MarkLogic Dev General] Displaying document after an update

I need to display a document right after a call to xdmp:node-replace() is made, 
and I'm able to achieve this by using a semi-colon to place them in separate 
transactions.

                            xdmp:node-replace($environment, $new-environment);

                            fn:doc("/release-tracking/components/2.xml")

Problem is, only the first transaction has enough data to derive the URI of the 
document to be displayed.

Thus my hardcoding the path in the second transaction.

Is there a way to pass this URI from the first to the second transaction ?

Or is there another / better way of displaying the doc after the update ?

Regards,

Danny




_______________________________________________
General mailing list
[email protected]<mailto:[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

Reply via email to