I'm surprised it worked in 8.7 - I thought this optimization had been in the product much longer than that.

If variables aren't used, then they aren't evaluated. You can't declare a variable just in order to achieve side-effects. Even if the variables are evaluated, you can't rely on the order in which they are evaluated.

Basically, to fool Saxon into executing non-deterministic functions like these, you have to pretend to make use of the result (in effect, you're simulating a monad). If the external methods return void, then the delivered result will be an empty sequence, and if you include this empty sequence in your query result, this will force Saxon to evaluate the function and thus trigger the side-effects. For example, if you called your three $doc variables $doc1, $doc2, and $doc3, you could simply do

return <response>{$doc1, $doc2, $doc3/response/*}</response>

Note that even this might not be enough to ensure that the variables are evaluated in the right order. To achieve that, you need to make the evaluation of a variable functionally dependent on the results of actions that you want to precede it.

Michael Kay

On 23/02/2013 20:08, Boysen, Pete [ITACD] wrote:

The following xquery worked in 8.7 but not in  All but the copyResources extension is ignored.


xquery version "1.0";

declare namespace QueryUpdate = "java:edu.iastate.its.thinkspace.core.xquery.QueryUpdate";

declare namespace SpaceFileService = "java:edu.iastate.its.thinkspace.core.filesystem.SpaceFileService";


declare variable $spaceFileService external;

declare variable $state external;

declare variable $_operationType external;

declare variable $user external;

declare variable $upd external;

declare variable $args external;


let $status := 0

let $root := concat('/space/',$args/args/pid/.,'/')

let $profile :=

<profile _n="2" background="white" layout="60%,40%" id="{$args/args/pid/.}" help="true" theme="EnterpriseBlue">


      <app column="0" id="addapp" minimized="false" name="Apps" type="addapp" url=""/>

      <app column="0" id="profileapp" minimized="false" name="Profile" type="profileapp"


      <app column="1" id="spacesapp" minimized="false" name="my Spaces" type="spacesapp"


      <app column="1" id="portfolioapp" minimized="false" name="My Portfolios"



      <app column="2" id="libraryapp" minimized="false" name="My Docs" type="libraryapp"




let $dirs :=  ('lib/','logs/','lib/archives/','lib/templates/','lib/public/')

let $doc := SpaceFileService:makeDirectories($spaceFileService,$state,$root,$dirs)

let $doc := QueryUpdate:createDoc($upd,concat($root,'profile.xml'),$profile)

let $files := '/gwt/ckeditor/styles.js,/gwt/ckeditor/templates.js'

let $doc := SpaceFileService:copyResources($spaceFileService,$state,$files,concat($root,'lib/templates/'))







Pete Boysen(pboysen@iastate.edu)

Information Technology Services

209 Durham



Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:

saxon-help mailing list archived at http://saxon.markmail.org/