[xquery-talk] flowrrr - how to structure a function?

Michael Kay mhk at mhk.me.uk
Tue Oct 17 14:07:11 PDT 2006


It looks reasonable to me. I'm not quite sure why you want the variable
$is-valid, since it's only used once, but if you do want it then this is the
way to write it.

Odd to see that this habit of sticking "fn:" in front of function names is
catching on even with XSLTers. I never use it myself, it seems to achieve
nothing but ugliness and redundancy. And inconsistency - you use doc() but
fn:string(). But tastes vary...

Michael Kay
http://www.saxonica.com/ 


> -----Original Message-----
> From: talk-bounces at x-query.com 
> [mailto:talk-bounces at x-query.com] On Behalf Of Robert Koberg
> Sent: 17 October 2006 11:16
> To: talk at x-query.com
> Subject: [xquery-talk] flowrrr - how to structure a function?
> 
> Hi, (I am a newbie)
> 
> Is it appropriate (necessary?) to nest return statements.
> 
> Is there a better way to write the function below? I only 
> want to get the $db-ref string and $db-instance nodeset 'if 
> the user is valid'.
> 
> -------------------------------
> declare function local:enter-project() as element()? {
>    let $is-valid := local:is-valid-user-for-group()
>    return
>      if ($is-valid) then
>        let $db-ref := request:get-parameter("db-ref", ""),
>            $db-instance := doc(databases.xml")/*/instance[@id=$db-ref]
>        return
>          (
>            session:set-attribute("rest-db-uri",
> fn:string($db-instance/rest-uri)),
>            session:set-attribute("xmlprc-db-uri",
> fn:string($db-instance/xmlprc-uri)),
>            session:set-attribute("webdav-db-uri",
> fn:string($db-instance/webdav-uri)),
>            session:set-attribute($project-key, $group-name),
>            response:redirect-to(xs:anyURI("./project/"))
>          )
>      else
>        <p class="warn">Could not find credentials to let you 
> enter the project.</p> };
> 
> thanks,
> -Rob
> 
> 
> 
> _______________________________________________
> talk at x-query.com
> http://x-query.com/mailman/listinfo/talk



More information about the talk mailing list