From: Ron V. d. B. <ron...@ka...> - 2008-03-03 09:53:38
|
Hi, I think I have solved a similar problem: I wanted an extensible query form that could pass a theoretically indefinite number of search terms to my XQuery script (still before the XForms age, don't even know if this is why XForms was designed for). Those 'extensible' parameters have fixed names, suffixed with a counter, like "field1", "range1", "term1", "mode1", "scope1", "operator1". Each new form entry row will create an incremented set of these parameter names: "field2", "range2", "term2", "mode2", "scope2", ... I tackled this problem as follows: 1) Determine the total of the 'extensible' parameters, by counting how many times one of them occurs (using request:get-parameter-names()). 2) Get the parameter values with request:get-parameter(), by looping over the parameter names. The names for the parameters are computed by concatenating the parameter names with their respective ranking numbers. let $parCount := count(request:get-parameter-names()[starts-with(., 'term')]) let $formItems := for $nr in 1 to $parCount return <query>{ string-join( (request:get-parameter(concat("field", $nr), ""), request:get-parameter(concat("range", $nr), " "), request:get-parameter(concat("term", $nr), ""), request:get-parameter(concat("mode", $nr), ""), if (request:get-parameter(concat("scope", $nr), "")) then request:get-parameter(concat("scope", $nr), "") else '1', request:get-parameter(concat("operator", $nr), "")), "#_#") }</query> The $formItems variable is then used further in the XQuery script to build the filtering predicate for my query expression. [Note that the values are concatenated to a string, in order to avoid the construction of temporary fragments in a read-only database, when querying the $formItems variable further in the XQuery script.] Kind regards, Ron |