Hi Paul,

I am not particular fan of this, but you could compress your if to:

let $a := ($params/author/text(), "")[1]

That would also remove multiple occurences of author element in $params..

You can indeed make your function accept an empty string parameter, or overload 
the function (redefining the same function with a different number of 
parameter, e.g. none, and have this second function call the first with default 
values for some of the parameters).

You can then initializing this $a inside the function if you like. But this can 
only be done if you either don't really need this value for doing whatever your 
function does and are able to give a proper response even when the parameter is 
empty. Or there is a default value that can always be applied, the empty string 
sounds like a possible candidate.

But it really depends on what the function does, whether or not to allow the 
empty string parameter.

You could say that the question mark behind the parameter indicates it is an 
optional parameter. Can you truly say that the parameter is optional?

HTH.

Kind regards,
Geert

>


Drs. G.P.H. Josten
Consultant


http://www.daidalos.nl/
Daidalos BV
Source of Innovation
Hoekeindsehof 1-4
2665 JZ Bleiswijk
Tel.: +31 (0) 10 850 1200
Fax: +31 (0) 10 850 1199
http://www.daidalos.nl/
KvK 27164984
De informatie - verzonden in of met dit emailbericht - is afkomstig van 
Daidalos BV en is uitsluitend bestemd voor de geadresseerde. Indien u dit 
bericht onbedoeld hebt ontvangen, verzoeken wij u het te verwijderen. Aan dit 
bericht kunnen geen rechten worden ontleend.


> From: [email protected]
> [mailto:[email protected]] On Behalf Of Paul M
> Sent: woensdag 10 juni 2009 23:18
> To: [email protected]
> Subject: [MarkLogic Dev General] Good Practice with Params
>
> I have the following
> url :  &author=TOM
>
> I have xqy function that places this into an element params..
> let $params := <params><author>TOM</author></params>
>
> I use this variable as such
>
> let $a := if (fn:boolean($params/author/text())) then
> $params/author/text() else ""
> return myfunc:hi($a)
>
> The above variable is tested because of the following:
> define function myfunc:hi($a as xs:string) This will through
> exception if $a is empty.
>
> Would this be considered good practice/best practice..
> I have other ideas:
>
> myfunc:hi($as as xs:string?)
> and alter function if needed
>
> create new function
> myfunc:init-params($params as element(params)) and initialize
> all variables  here
>
> thoughts, experience, caveats ?
> /text()
> empty variable
> strings
>
> etc...
>
>
>
>

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

Reply via email to