Hi Abishek, Sorry, I think I had some quotes too many around $fragment, that still results in a string being passed as first param to cts:search.
Yes dirty, but equally dirty as xdmp:value on $fragment alone. Much less readable though. Perhaps it would be interesting if cts:search would accept a string (or a variable containing a string) as first param, but you would miss out on some things like, warnings about non-searchable expressions at 'compile' time. Not even sure if Mark Logic could make it work.. Now you mention utility, have you looked into the search:search library? It takes a different style of parameters and options, but can do the same. It can even help you simplify some common yet powerfull search tricks. Good luck, Geert Van: [email protected] [mailto:[email protected]] Namens Abishek N Verzonden: vrijdag 18 februari 2011 17:27 Aan: [email protected] Onderwerp: Re: [MarkLogic Dev General] xs:string to xpath It took me a lil while to get to this working..it needs more attention where ever there are commas I agree with you this is a dirty way to do it.. I wish I could write a utility that would take care of such stuff.. declare namespace ns = "http://addware.com/xmlschemas/report/1"; let $fragment := "//ns:address" let $expression := fn:concat('cts:search(', $fragment, ',cts:and-query((cts:document-query("doc.xml")', ',cts:element-range-query(xs:QName("ns:name")', ',"="', ',"John Doe")))', ',"unfiltered")' ) return xdmp:value($expression) On Thu, Feb 17, 2011 at 6:42 PM, Abishek N <[email protected]<mailto:[email protected]>> wrote: Hello I know this sounds quite simple, but I have not been able to accomplish this. Let me consider the following eg. I am trying to run a search on a single document on the fragament root //ns:address xquery version "1.0-ml"; declare namespace ns = "http://www.addware.com/xmlschemas/report/1"; let $result := cts:search(//ns:address, cts:and-query(( cts:document-query("doc.xml"), ((cts:element-range-query(xs:QName("ns:name"),"=","John Doe"))))),'unfiltered') similarly based on the request if i were to run the search based on the user name in various fragament roots for eg //ns:insurance or //ns:contactnumber based on the user name can I parameterize the fragament root //ns:address such that I dont have to write multiple search queries? here is what I tried, lets say I have a metadata xml file which tells be if the request is for "ad", then look for the results in the fragament roots //ns:address if it for "phone", then look for results in the fragament root //ns:contactnumber which would be returned as a xs:string even though I read it from the metadata file, when I do an unquote it tells me that this is not a searchable expression. metadata file would be like this <list> <frags> <type>ad</type> <searchfrag>//ns:address</searchfrag> </frags> <frags> <type>phone</type> <searchfrag>//ns:contactnumber</searchfrag> </frags> <frags> <type>ins</type> <searchfrag>//ns:insurance</searchfrag> </frags> </list> let $result := cts:search(xdmp:unquote("//ns:address"), cts:and-query(( cts:document-query("doc.xml"), ((cts:element-range-query(xs:QName("ns:name"),"=","John Doe"))))),'unfiltered') i found an another way let $result := cts:search(if($attr="ad") then //ns:address else if ($attr="phone") then //ns:contactnumber else //ns:insurance, cts:and-query(( cts:document-query("doc.xml"), ((cts:element-range-query(xs:QName("ns:name"),"=","John Doe"))))),'unfiltered') -- Regards Abishek -- Regards Abishek
_______________________________________________ General mailing list [email protected] http://developer.marklogic.com/mailman/listinfo/general
