marklogicmarklogic-8

Multi statement variables in ML8


I am trying to execute Multi statement transaction with semi-colon as a statement separator. I have external variables in my script and these are only accessible on the first statement in the multi-step.. for second statement xdmp:document-add-properties I get XDMP-UNEXPECTED.. Following is my code

      let $sub-query := 'xquery version "1.0-ml";
                         declare option xdmp:transaction-mode "update";
                         declare variable $newDocUri  external;
                        declare variable $transformed_annotations external;
                        declare variable $uri external;
                        declare variable $app  external;
                        declare variable $id external;

                        xdmp:document-insert($newDocUri, $transformed_annotations,(xdmp:default-permissions()), ("annotated", "termite", $app));
                        xdmp:document-add-properties($newDocUri, (<document-parent-location>{$uri}</document-parent-location>,
                                                                        <context>{$app}</context>,
                                                                        <id>{$id}</id>))
                        xdmp:commit()
                    '

                    let $_ := xdmp:eval($sub-query, (
                                                    xs:QName("newDocUri"),$newDocUri,
                                                    xs:QName("transformed_annotations"), $transformed_annotations,
                                                    xs:QName("uri"), $uri,
                                                    xs:QName("app"), $app,
                                                    xs:QName("id"), $id
                                                    ), <options xmlns="xdmp:eval">
                                                            <isolation>different-transaction</isolation>
                                                        </options>)

Solution

  • In your second (and any future subsequent) statements, you need to redeclare the XQuery prolog, including any external variable declarations you will need in that query.