Hi Santhosh,

Oh right, I am still a bit used to XPath 1.0 in which is specified that the 
number and string functions simply take the first item from a node-set argument.

There are plenty ways around this problem. But it really depends what you are 
actually searching for. I'll leave out the cts:search for simplicity..

This:
        doc()[number((.//priority)[1]) eq  number((.//eligible-flag)[1])] 

Will return documents in which the value of the first occurrence of priority 
element is (numerically) compared with the value of the first occurrence of 
eligible-flag.

This:
        doc()[.//priority = .//eligible-flag] 

Will return documents in which there is any priority element whose value 
(lexically) matches with the value of eligible-flag element. (You can probably 
use the eq just as well here.)

This:
        doc()[.//priority[. eq ../eligible-flag] ]

Will return documents in which there is a priority element whose value matches 
with the value of sibling eligible-flag element.

But to be honest, I wasn't expecting the priority and eligible-flag elements to 
occur multiple times in one document, since the original poster was using 
search functions. And I guess that happened to be true as you are getting 
exceptions, but Deepak isn't.. ;-)

Kind regards,
Geert

> -----Original Message-----
> From: [email protected] 
> [mailto:[email protected]] On Behalf Of 
> Santhosh Raj
> Sent: woensdag 6 mei 2009 11:56
> To: General Mark Logic Developer Discussion
> Subject: RE: [MarkLogic Dev General] Comparision of values 
> within the node (was: [email protected])
> 
> 
> HI Geert, 
> 
>         cts:search(doc(), "*")[number(.//priority) eq  
> number(.//eligible-flag)] 
> 
> returns XDMP-ARGTYPE error. 
> 
> <error:message>Invalid argument type</error:message>
>   <error:format-string>XDMP-ARGTYPE: (err:XPTY0004) 
> number((doc("mohan.xml")/nodes/node[1]/priority, 
> doc("mohan.xml")/nodes/node[2]/priority, 
> doc("mohan.xml")/nodes/node[3]/priority, ...)) -- arg1 is not 
> of type xs:anyAtomicType?</error:format-string> 
> 
> My xml content is : 
> 
>     <nodes> 
>       <node> 
>              <priority>1</priority> 
>              <eligible-flag>1</eligible-flag> 
>       </node> 
>       <node> 
>              <priority>2</priority> 
>              <eligible-flag>2</eligible-flag> 
>       </node> 
>       <node> 
>              <priority>2</priority> 
>              <eligible-flag>0</eligible-flag> 
>       </node> 
>       <node> 
>              <priority>5</priority> 
>              <eligible-flag>2</eligible-flag> 
>       </node> 
>       <node> 
>              <priority>8</priority> 
>              <eligible-flag>1</eligible-flag> 
>       </node>
> </nodes> 
> 
> Santhosh Rajasekaran
> Tata Consultancy Services
> Mailto: [email protected]
> Website: http://www.tcs.com <http://www.tcs.com/> 
> ____________________________________________
> Experience certainty.        IT Services
>                        Business Solutions
>                        Outsourcing
> ____________________________________________ 
> 
> 
> 
> Geert Josten <[email protected]> 
> Sent by: [email protected] 
> 
> 05/06/2009 02:24 PM 
> Please respond to
> General Mark Logic Developer Discussion 
> <[email protected]>
> 
> To
> General Mark Logic Developer Discussion 
> <[email protected]> 
> cc
> Subject
> RE: [MarkLogic Dev General] Comparision of values within the 
> node        (was: [email protected])
> 
>       
> 
> 
> 
> 
> Hi Deepak,
> 
> To my knowledge, you cannot express a comparison between node 
> values in cts:query functions. You will have to search for 
> documents containing these elements first with cts:search, 
> and apply a XPath predicate on the resulting nodes, which 
> restricts the results to the nodes that meet your criterium. 
> For instance by doing something like this:
> 
>        cts:search(doc(), "*")[number(.//priority) eq  
> number(.//eligible-flag)]
> 
> Though, if you know the exact values you are searching, then 
> you can simply test for those values in both elements. For 
> instance like:
> 
>        let $some-values := ("1", "2", "3")
>        return
>                cts:search(doc(),
>                        cts:and-query((
>                                
> cts:element-value-query(xs:QName("priority"), $some-values),
>                                
> cts:element-value-query(xs:QName("eligible-flag"), $some-values)
>                        ))
>                )
> 
> Kind regards,
> Geert
> 
> >
> 
> 
> Drs. G.P.H. Josten
> Consultant
> 
> 
> http://www.daidalos.nl/ <http://www.daidalos.nl/> 
> Daidalos BV
> Source of Innovation
> Hoekeindsehof 1-4
> 2665 JZ Bleiswijk
> Tel.: +31 (0) 10 850 1200
> Fax: +31 (0) 10 850 1199
> http://www.daidalos.nl/ <http://www.daidalos.nl/> 
> KvK 27164984
> De informatie - verzonden in of met dit emailbericht - is 
> afkomstig van Daidalos BV en is uitsluitend bestemd voor de 
> geadresseerde. Indien u dit bericht onbedoeld hebt ontvangen, 
> verzoeken wij u het te verwijderen. Aan dit bericht kunnen 
> geen rechten worden ontleend.
> 
> 
> > From: [email protected]
> > [mailto:[email protected] 
> <mailto:[email protected]> ] On Behalf Of
> > deepak mohan
> > Sent: woensdag 6 mei 2009 10:19
> > To: [email protected]
> > Subject: [MarkLogic Dev General] [email protected]
> >
> >
> > Hi Chaps,
> >
> >      I want to search for a node based on the comparision of
> > values within the node. Could you please send me a cts:query
> > for the above critertia.
> >
> > for eg: The node looks like this:
> >
> >       <node1>
> >              <priority>1</priority>
> >              <eligible-flag>1</eligible-flag>
> >       </node1>
> >       <node2>
> >              <priority>2</priority>
> >              <eligible-flag>2</eligible-flag>
> >       </node2>
> >       <node3>
> >              <priority>2</priority>
> >              <eligible-flag>0</eligible-flag>
> >       </node3>
> >
> > I want to select the node if the priority and eligible has
> > the same value....
> >
> > thanks in advance,
> > Deepak M.
> >
> >
> >
> >
> >
> >
> >
> > ________________________________
> >
> > Now surf faster and smarter ! Check out the new Firefox 3 -
> > Yahoo! Edition * Click here!
> > 
> <http://in.rd.yahoo.com/tagline_firefox_1/*http://downloads.ya
>  <http://in.rd.yahoo.com/tagline_firefox_1/*http://downloads.ya> 
> > hoo.com/in/firefox/?fr=om_email_firefox>
> >
> 
> _______________________________________________
> General mailing list
> [email protected]
> http://xqzone.com/mailman/listinfo/general 
> <http://xqzone.com/mailman/listinfo/general> 
> 
> ForwardSourceID:NT0000AE9A     
> 
> =====-----=====-----=====
> Notice: The information contained in this e-mail
> message and/or attachments to it may contain 
> confidential or privileged information. If you are 
> not the intended recipient, any dissemination, use, 
> review, distribution, printing or copying of the 
> information contained in this e-mail message 
> and/or attachments to it are strictly prohibited. If 
> you have received this communication in error, 
> please notify us by reply e-mail or telephone and 
> immediately and permanently delete the message 
> and any attachments. Thank you
> 
> 
> _______________________________________________
General mailing list
[email protected]
http://xqzone.com/mailman/listinfo/general

Reply via email to