Re: Handling variable number of parameters.
Adam Retter <adam.retter <at> devon.gov.uk>
2008-03-01 16:39:00 GMT
When you say a variable number of arguments, how variable are we talking?
Is it just that these two variables (below) may of may not appear?
request:get-parameter("after_time",())
request:get-parameter("before_time",())
Thanks Adam.
-----Original Message-----
From: exist-open-bounces <at> lists.sourceforge.net on behalf of Jasen Jacobsen
Sent: Fri 29/02/2008 22:14
To: exist-open <at> lists.sourceforge.net
Subject: [Exist-open] Handling variable number of parameters.
I hope/think there is a better way to do this.
I am attempting to write an XQuery that handles a variable number of
arguments from the HTTP request parameters.
like:
let $after_time := request:get-parameter("after_time",())
let $before_time := request:get-parameter("before_time",())
Then I want to build an xpath expression like:
/db/collection('MyStuff')/event[(xs:dateTime( <at> start) >
xs:dateTime($after_time)) and (xs:dateTime( <at> start) <
xs:dateTime($before_time))]
but I want to be smart about detecting whether the $after_time and
$before_time have been provided and build the predicate appropriately.
So if there is no $after_time parameter the xpath would look like:
/db/collection('MyStuff')/event[(xs:dateTime( <at> start) <
xs:dateTime($before_time))]
Currently, I've resorted to writing a Java extension module that
builds up the predicate string and passes it back to the XQuery
engine. I tried building the predicate as a string within XQuery
(with my limited knowledge) and it just got ridiculously complicated.
I could do something like get ALL the <event>s and then further filter
the results one at a time, something like:
(: get all events :)
let $result := /db/collection('MyStuff')/event
(: get the before events :)
let $result :=
if (not(empty($before_time)) then
$result[(xs:dateTime( <at> start) < xs:dateTime($before_time))]
else $result
But that seems a little hokey - although no more hokey than jumping
out to Java, buidling a string, passing it back, and using the result
as the predicate, I guess. My concern with this step by step method
is that if the original set is very large, things may get a bit bogged
down.
Advice?
- Jasen.
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Exist-open mailing list
Exist-open <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/exist-open
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Exist-open mailing list
Exist-open <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/exist-open