From: Mike S. <so...@if...> - 2009-06-17 18:34:53
|
I couldn't see the bold in your plain text e-mail, but I'm guessing you get a namespace declaration error in "eval". I'm pretty sure you need to add your namespace declaration to the string you are evaluating, like: let $nsdecl = 'declare namespace ms="http://myNamespace/1.1/"; ' ... util:eval (concat ($nsdecl, $query_string)) ... -Mike PencilEd wrote: > I really have no idea why this isn't working... It really should, in fact > - I've tried to do this exact thing in the eXist sandbox (I've copied and > pasted my actual code and the code I tried in Sandbox). It works fine in > sandbox, and should work in my application... but doesn't. > I've bolded the 2 lines that are throwing the error (saying the namespace > isn't defined). I declare the namespace at the beginning and my other > function has no trouble recognizing it. I really don't understand why the > 2nd function is so blind. I've read through the util:eval documentation and > it states that it is aware of the state from which it was called (so it > should be aware of variables). > Am I mistaken? If so... how can I work around that? If I'm not > mistaken... what am I doing wrong? > Please help> > Thanks - code below. > > --- Start Error --- > Error found > Error while evaluating expression: > collection('/db/test1.1')/ms:Resource[.//*[matches(data(.), 'd', 'i')]]. > XPST0081: No namespace defined for prefix ms [at line 77, column 22] > --- End Error --- > > > --- Start Sandbox Code --- > import module namespace util="http://exist-db.org/xquery/util"; > > declare namespace ms="http://myNamespace/1.1/"; > declare variable $collection_all := "/db/test1.1"; > > let $escaped_string := "d" > let $collection := concat("collection('", $collection_all, "')/ms:Resource") > let $search_condition := concat("matches(data(.), '", $escaped_string, "', > 'i')") > let $search_location := "" > > let $query_string := concat($collection, '[.//*[', $search_location, > $search_condition, ']]') > > let $hits := util:eval($query_string) > return $hits > --- End Sandbox Code --- > > > > > --- Start Code --- > xquery version "1.0" encoding "UTF-8"; > > module namespace msc_fun="http://localhost:8080/exist/msc"; > import module namespace util="http://exist-db.org/xquery/util"; > > declare namespace ms="http://myNamespace/1.1/"; > declare variable $msc_fun:collection_all := "/db/test1.1"; > > declare function msc_fun:dd_element_names($selected as xs:string?) as > node()* { > for $element in msc_fun:distinct_element_names() > > return <option value='{$element}'>{substring($element, 4)}</option> > }; > > declare function msc_fun:distinct_element_names () as xs:string* { > let $myNode := collection($msc_fun:collection_all)/ms:Resource[1] > > return distinct-values($myNode/child::*/name(.)) > } ; > > declare function msc_fun:process($element as xs:string, $input as xs:string, > $exact as xs:string, $start as xs:integer, $perpage as xs:integer) as > node()* { > let $result := msc_fun:query_data($element, $input, $exact, $start, > $perpage) > let $total := count($result) > > return ... output... > }; > > declare function msc_fun:query_data($element as xs:string, $input as > xs:string, $exact as xs:string, $start as xs:integer, $perpage as > xs:integer) as node()* { > let $escaped_string := msc_fun:escape_string($input) > let $collection := concat("collection('", $msc_fun:collection_all, > "')/ms:Resource") > let $search_condition := if ($exact = 'yes') > then concat("upper-case(data(.)) = upper-case('", $input, "')") > else concat("matches(data(.), '", $escaped_string, "', 'i')") > let $search_location := if ($element = 'any') > then "" > else concat("name() = '", $element, "' and ") > > let $query_string := concat($collection, '[.//*[', $search_location, > $search_condition, ']]') > > let $hits := util:eval($query_string) > > for $resource at $div_id in $hits > return msc_fun:query_data_results($resource, $element, $div_id) > }; > --- End Code --- > |