Hi Geert,

It makes sense, but I'd like to call just one function that receives
multiple parameters:

- existing database value
- request field name
- action
- new value

When invoked, the function uses the action to determine what value should be
assigned to a local variable and sets a status if the values differ.  So
rewriting my example we have:

xquery version "1.0-ml";

declare namespace t = "test";
declare variable $t:changed := false();

declare function t:working-value($action, $db-value, $request-field,
$new-value)
{
    let $form-value := 
        if ($action eq ("Get", "Save")) then
xdmp:get-request-field($request-field) else ()
    return
        if ($action eq "New") then $new-value
        else if ($action eq "Retrieve") then (
            $db-value,
            if (not($t:changed) and $db-value ne $form-value) then
xdmp:set($t:changed, true()) else ()           
        )
        else if ($action eq "Save") then (
            $form-value,
            if (not($t:changed) and $db-value ne $form-value) then
xdmp:set($t:changed, true()) else ()
        )
};

let $name := t:working-value("Save", "Joe", "Name", "")
let $position := t:working-value("Save", "Joe", "Name", "")
(: let $local-var := t:working-value(...) :)

return (
    if ($save) 
        then (: build XML document using name, position, ... 
                and insert it into the database :) 
        else (),
    (: populate form :)
)

Cool?

Tim

-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Geert Josten
Sent: Thursday, September 15, 2011 10:54 AM
To: General MarkLogic Developer Discussion
Subject: Re: [MarkLogic Dev General] How to effectively pass variables by
reference to an xquery function?

Hi Tim,

Ah. In that case I would have written a 'has-changed' function, that returns
a Boolean. You apply that to all values first, and check for trues and
falses after that. You can do that more fixed, but you could also collect
Boolean in a sequence and look for a true in that as well. Makes sense?

Kind regards,
Geert



_______________________________________________
General mailing list
[email protected]
http://developer.marklogic.com/mailman/listinfo/general

Reply via email to