Hi Abishek,
Hmm, okay. Perhaps this is not the right way to do it. The first param to
cts:search is treated in a special way. You could say that it is an unevaluated
expression. Xdmp:value evaluates your xpath though, so the cts:search is
receiving the actual ns:address nodes themselves, not the unevaluated
expression. Now I see why you thought about using xdmp:unquote. Unfortunately
that doesn't work, as you saw. I am afraid there isn't really a nice way to do
this, other than use concat and pass the whole cts:search expression as a
string to xdmp:value. Something like this:
let $fragment :=$node/frags[type= "ad"]/searchfrag/text()
let $expression := concat(
'cts:search("',
$fragment,
'", cts:and-query((cts:document-query("doc.xml"),
((cts:element-range-query(xs:QName("ns:name"),"=","John Doe"))))),"unfiltered")'
)
let $result := xdmp:value($expression)
Kind regards,
Geert
Van: [email protected]
[mailto:[email protected]] Namens Abishek N
Verzonden: vrijdag 18 februari 2011 15:31
Aan: [email protected]
Onderwerp: Re: [MarkLogic Dev General] xs:string to xpath
Hello Geert thanks for your response..
So should I substitute xdmp:unquote with xdmp: value? I tried that but I get
the following error.
XDMP-UNSEARCHABLE: cts:search(xdmp:value(text{"//ns:address"}),
cts:or-query(cts:document-query("doc.xml"))) -- Expression is unsearchable
Is there something wrong I am doing here.. I have explained in detail below
(: this is the constants which has mapping :)
let $node :=
<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>
(:I get the fragment root for ad and i notice it to have the value as
//ns:address :)
let $fragment :=$node/frags[type= "ad"]/searchfrag/text()
let $result :=
cts:search(xdmp:value($fragment),
cts:and-query((
cts:document-query("doc.xml"),
((cts:element-range-query(xs:QName("ns:name"),"=","John Doe"))))),'unfiltered')
as said above i get the same exception
On Thu, Feb 17, 2011 at 6:55 PM, Abishek N
<[email protected]<mailto:[email protected]>> wrote:
Apologies Missed out the actual question..
Is there a better way than the third approach that I had given?
I similar to unquote I have also tried fn:QName but no luck
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 fragment 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 fragment roots
for eg //ns:insurance or //ns:contactnumber based on the user name can I
parameterize the fragment 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 fragment 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 search able
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')
Thanks
AN
--
Regards Abishek
_______________________________________________
General mailing list
[email protected]
http://developer.marklogic.com/mailman/listinfo/general