Re: Incorrect "No result for query" for XPath expression
David Vergnaud <[email protected]> Thu, 22 Oct 2009 03:14:55 -0700 (PDT)
| Newsgroups | gmane.text.xml.xindice.user |
|---|---|
| Message-ID | <[email protected]> |
Hi Natalia,=0A=0Athx a lot for your reply and making this clear to me. I th= ought the default behaviour for functions such as contains() when receiving= a set of text nodes as argument was to apply the processing to each node s= eparately and in turn return a set of booleans. Seeing as this is wrong, I = perfectly get your point. As it appears, the online tool I used to check my= claim made the same incorrect assumption.=0A=0AAgain thanks and regards,= =0A=0ADavid=0A=0A=0A=0A----- Original Message ----=0AFrom: Natalia Shilenko= va <[email protected]>=0ATo: [email protected]=0ASent: Thu, = October 22, 2009 12:13:55 AM=0ASubject: Re: Incorrect "No result for query"= for XPath expression=0A=0ADavid,=0A=0AThe problem you're describing is not= a bug, your XPath query is executed correctly.=0A=0ALet's see what happens= when query /martif/text/body/termEntry[contains(langSet/ntig/termGrp/term/= text(),'bancaire')] is executed. First, XPath finds all nodes with path /m= artif/text/body/termEntry/langSet/ntig/termGrp/term and selects their child= ren text nodes. The result of this step is node-set, which includes <term> = data for every language. Then, XPath evaluates function contains(), where f= irst argument is node-set. Per XPath specification [1], function contains e= xpects two arguments of type string, not node-set, so it converts the first= argument to string using function string(). When applied to node-set, it r= eturns string value of the _first_ node in the document order.=0A=0AInstead= of checking <term> data for every language, it just checks if <term> data = contains given string for language that happened to be first in the documen= t. You can easily verify that by rearranging order of langSet tags in the d= ocument. The query /martif/text/body/termEntry[contains(langSet[starts-with= (@lang,'fr')]/ntig/termGrp/term/text(),'bancaire')] works because of the sa= me reason: contains() function only gets one langSet.=0A=0AIf you want the = query that would check all the text nodes to see if they contain some subst= ring, you can try something like that:=0A/martif/text/body/termEntry[langSe= t/ntig/termGrp/term[contains(text(),'bancaire')]]=0A=0A[1] http://www.w3.or= g/TR/1999/REC-xpath-19991116=0A=0ARegards,=0ANatalia=0A=0A=0AOn Oct 21, 200= 9, at 12:02 PM, David Vergnaud wrote:=0A=0A> Hi,=0A> =0A> I'm reporting on = a problem which I'm pretty much convinced is a bug in the current 1-2.dev v= ersion of Xindice (1.2m1). I'm using Xindice running on its own (no Tomcat)= as a daemon on a Linux box (Suse 11) with JDK 1.6.=0A> =0A> Basically, I h= ave a DB where I've stored terminology entries that contain information abo= ut various banking terms in 4 languages. I want to be able to conduct two t= ypes of searches, one where the term is searched for only one of the langua= ges, and one where the search is carried out in all languages. For this, I = use two versions of a somewhat complicated XPath expression: one where the = language is specified (as attribute of one of the nodes, in a predicate) an= d one where it isn't. This is the only difference between the two expressio= ns. Surprisingly, the one where the language is fixed does return results w= here the one without specification doesn't. Besides, I've tested the XPath = expression on other systems, and seen that there really should be results.= =0A> =0A> The first impression is that when evaluating function arguments i= nside a predicate, only the first node of a node set is evaluated. In my ca= se, that would be confirmed by the following fact: each entry contains firs= t the German word, then either French or English. When doing an "unrefined"= search (no language specification) with a German word, results are returne= d. When doing the same unrefined search with French or English, no results = are returned.=0A> =0A> Here's an example of an XPath we're using, first wit= h the language refinement, then without:=0A> /martif/text/body/termEntry[co= ntains(langSet[starts-with(@lang,'fr')]/ntig/termGrp/term/text(),'bancaire'= )]=0A> /martif/text/body/termEntry[contains(langSet/ntig/termGrp/term/text(= ),'bancaire')]=0A> =0A> As you can see, the goal is to extract a termEntry = element which contains the word "bancaire" under the specified path. In the= first path, I set the langSet to have attribute lang start with "fr" (for = French), in the second I don't. As I said before, the first expression yiel= ds a result and the second one doesn't.=0A> =0A> I'm including an example D= B entry which can be used to test this -- I assume it should be possible to= observe this behaviour with only one entry in the DB as well. In order to = use the xpath above with it, one would need to prefix all node names in the= xpath expression with "tbx" (I only removed that for legibility).=0A> =0A>= Should this prove to be an error on my side, I'd be grateful to anyone who= 'd point it out. Otherwise, it might need to be taken onto the Xindice bug = list.=0A> =0A> Cheers,=0A> =0A> David=0A> =0A> <?xml version=3D"1.0"?>=0A> = <martif xmlns=3D"http://www.lisa.org/tbx" type=3D"TBX" xml:lang=3D"de-CH">= =0A> <martifHeader>=0A> <fileDesc>=0A> <titleStmt>=0A> <tit= le>=0A> Test-TerminologieDB </title>=0A> </titleStmt>= =0A> <publicationStmt>=0A> <p>=0A> Version 1.1 = </p>=0A> </publicationStmt>=0A> <sourceDesc>=0A> <p>=0A> = Version 1.1 </p>=0A> </sourceDesc>=0A> </fileDesc>= =0A> </martifHeader>=0A> <text>=0A> <body>=0A> <termEntry>=0A> = <descrip type=3D"classificationCode" />=0A> <descrip type=3D"su= bjectField">=0A> </descrip>=0A> <langSet xml:lang=3D"de-CH">= =0A> <transacGrp>=0A> <transac type=3D"transactionType"= >=0A> created </transac>=0A> <transacNot= e type=3D"responsibility">=0A> STEA </transacNote>= =0A> <date>=0A> 2009-09-15T14:44:54.924+02:00 = </date>=0A> </transacGrp>=0A> <descrip type=3D"reli= abilityCode">=0A> 1 </descrip>=0A> <note />=0A= > <descripGrp>=0A> <descrip type=3D"definition">=0A> = Die Garantie ist eine selbstst=E4ndige, vom Hauptschuldverh=E4lt= nis unabh=E4ngige Verpflichtung. Der Garant (die Bank) kann keinerlei Einwe= ndungen und Einreden aus dem Grundgesch=E4ft erheben. Das heisst: Der Garan= t zahlt auf erste schriftliche Anforderung (Inanspruchnahme) des Beg=FCnsti= gten, gegen Einreichung der im Garantietext vorgeschriebenen Best=E4tigung = und allenfalls vorgeschriebenen Dokumente. </descrip>=0A> = <adminGrp>=0A> <admin type=3D"source">=0A> = CS Glossar </admin>=0A> </adminGrp>=0A> <= /descripGrp>=0A> <ntig>=0A> <termGrp>=0A> = <term>=0A> Bankgarantie </term>=0A> = <termNote type=3D"partOfSpeech" />=0A> <termNote type=3D"gra= mmaticalGender" />=0A> <termNote type=3D"grammaticalNumber" />= =0A> <termCompList type=3D"lemma">=0A> <termCom= p />=0A> </termCompList>=0A> <termCompList type= =3D"morphologicalElement">=0A> <termComp />=0A> = </termCompList>=0A> <termNote type=3D"termType">=0A> = main </termNote>=0A> <termNote type=3D"usa= geNote" />=0A> </termGrp>=0A> <adminGrp>=0A> = <admin type=3D"source">=0A> CS Glossar </a= dmin>=0A> <note />=0A> </adminGrp>=0A> <= descripGrp>=0A> <descrip type=3D"example" />=0A> = <adminGrp>=0A> <admin type=3D"source" />=0A> </= adminGrp>=0A> </descripGrp>=0A> <note />=0A> = </ntig>=0A> <ntig>=0A> <termGrp>=0A> <ter= m />=0A> <termNote type=3D"termType">=0A> abbr = </termNote>=0A> </termGrp>=0A> <adminGrp= >=0A> <admin type=3D"source" />=0A> </adminGrp>=0A>= </ntig>=0A> <ntig>=0A> <termGrp>=0A> = <term />=0A> <termNote type=3D"termType">=0A> = syn </termNote>=0A> <termNote type=3D"grammat= icalGender" />=0A> <termCompList type=3D"lemma">=0A> = <termComp />=0A> </termCompList>=0A> <termC= ompList type=3D"morphologicalElement">=0A> <termComp />=0A> = </termCompList>=0A> </termGrp>=0A> <admi= nGrp>=0A> <admin type=3D"source" />=0A> <note />= =0A> </adminGrp>=0A> <descrip type=3D"example" />=0A>= <adminGrp>=0A> <admin type=3D"source" />=0A> = </adminGrp>=0A> <note />=0A> </ntig>=0A> <= /langSet>=0A> <langSet xml:lang=3D"en-GB">=0A> <transacGrp>= =0A> <transac type=3D"transactionType">=0A> created= </transac>=0A> <transacNote type=3D"responsibility">= =0A> STEA </transacNote>=0A> <date>=0A> = 2009-09-15T14:44:54.924+02:00 </date>=0A> = </transacGrp>=0A> <descrip type=3D"reliabilityCode">=0A> = 1 </descrip>=0A> <note />=0A> <descripGrp>=0A>= <descrip type=3D"definition" />=0A> <adminGrp>=0A> = <admin type=3D"source" />=0A> </adminGrp>=0A> = </descripGrp>=0A> <ntig>=0A> <termGrp>=0A> = <term>=0A> bank guarantee </term>=0A> = <termNote type=3D"partOfSpeech" />=0A> <termNote type= =3D"grammaticalGender" />=0A> <termNote type=3D"grammaticalNum= ber" />=0A> <termCompList type=3D"lemma">=0A> <= termComp />=0A> </termCompList>=0A> <termCompList= type=3D"morphologicalElement">=0A> <termComp />=0A> = </termCompList>=0A> <termNote type=3D"termType">=0A> = main </termNote>=0A> <termNote type= =3D"usageNote" />=0A> </termGrp>=0A> <adminGrp>=0A> = <admin type=3D"source">=0A> CS Glossar = </admin>=0A> <note />=0A> </adminGrp>=0A> = <descripGrp>=0A> <descrip type=3D"example" />=0A> = <adminGrp>=0A> <admin type=3D"source" />=0A> = </adminGrp>=0A> </descripGrp>=0A> <note />=0A> = </ntig>=0A> <ntig>=0A> <termGrp>=0A> = <term />=0A> <termNote type=3D"termType">=0A> = abbr </termNote>=0A> </termGrp>=0A> <a= dminGrp>=0A> <admin type=3D"source" />=0A> </adminG= rp>=0A> </ntig>=0A> <ntig>=0A> <termGrp>=0A> = <term />=0A> <termNote type=3D"termType">=0A> = syn </termNote>=0A> <termNote type=3D"= grammaticalGender" />=0A> <termCompList type=3D"lemma">=0A> = <termComp />=0A> </termCompList>=0A> = <termCompList type=3D"morphologicalElement">=0A> <termComp = />=0A> </termCompList>=0A> </termGrp>=0A> = <adminGrp>=0A> <admin type=3D"source" />=0A> <n= ote />=0A> </adminGrp>=0A> <descrip type=3D"example" = />=0A> <adminGrp>=0A> <admin type=3D"source" />=0A>= </adminGrp>=0A> <note />=0A> </ntig>=0A> = </langSet>=0A> <langSet xml:lang=3D"fr-CH">=0A> <trans= acGrp>=0A> <transac type=3D"transactionType">=0A> c= reated </transac>=0A> <transacNote type=3D"responsibi= lity">=0A> STEA </transacNote>=0A> <date= >=0A> 2009-09-15T14:44:54.924+02:00 </date>=0A> = </transacGrp>=0A> <descrip type=3D"reliabilityCode">=0A> = 1 </descrip>=0A> <note />=0A> <descripGr= p>=0A> <descrip type=3D"definition" />=0A> <adminGrp>= =0A> <admin type=3D"source" />=0A> </adminGrp>=0A> = </descripGrp>=0A> <ntig>=0A> <termGrp>=0A> = <term>=0A> garantie bancaire </term>= =0A> <termNote type=3D"partOfSpeech" />=0A> <term= Note type=3D"grammaticalGender" />=0A> <termNote type=3D"gramm= aticalNumber" />=0A> <termCompList type=3D"lemma">=0A> = <termComp />=0A> </termCompList>=0A> <ter= mCompList type=3D"morphologicalElement">=0A> <termComp />=0A= > </termCompList>=0A> <termNote type=3D"termType"= >=0A> main </termNote>=0A> <termNo= te type=3D"usageNote" />=0A> </termGrp>=0A> <adminGrp= >=0A> <admin type=3D"source">=0A> CS Glossar = </admin>=0A> <note />=0A> </adminGrp>=0A= > <descripGrp>=0A> <descrip type=3D"example" />=0A>= <adminGrp>=0A> <admin type=3D"source" />=0A> = </adminGrp>=0A> </descripGrp>=0A> <note /= >=0A> </ntig>=0A> <ntig>=0A> <termGrp>=0A> = <term />=0A> <termNote type=3D"termType">=0A> = abbr </termNote>=0A> </termGrp>=0A> = <adminGrp>=0A> <admin type=3D"source" />=0A> <= /adminGrp>=0A> </ntig>=0A> <ntig>=0A> <termGrp= >=0A> <term />=0A> <termNote type=3D"termType">= =0A> syn </termNote>=0A> <termNote= type=3D"grammaticalGender" />=0A> <termCompList type=3D"lemma= ">=0A> <termComp />=0A> </termCompList>=0A> = <termCompList type=3D"morphologicalElement">=0A> <= termComp />=0A> </termCompList>=0A> </termGrp>=0A> = <adminGrp>=0A> <admin type=3D"source" />=0A> = <note />=0A> </adminGrp>=0A> <descrip type=3D"= example" />=0A> <adminGrp>=0A> <admin type=3D"sourc= e" />=0A> </adminGrp>=0A> <note />=0A> </nti= g>=0A> </langSet>=0A> <langSet xml:lang=3D"it-CH">=0A> = <transacGrp>=0A> <transac type=3D"transactionType">=0A> = created </transac>=0A> <transacNote type=3D"r= esponsibility">=0A> STEA </transacNote>=0A> = <date>=0A> 2009-09-15T14:44:54.924+02:00 </date= >=0A> </transacGrp>=0A> <descrip type=3D"reliabilityCode"= >=0A> 1 </descrip>=0A> <note />=0A> <= descripGrp>=0A> <descrip type=3D"definition" />=0A> <= adminGrp>=0A> <admin type=3D"source" />=0A> </admin= Grp>=0A> </descripGrp>=0A> <ntig>=0A> <termGrp= >=0A> <term>=0A> garanzia bancaria = </term>=0A> <termNote type=3D"partOfSpeech" />=0A> = <termNote type=3D"grammaticalGender" />=0A> <termNote type= =3D"grammaticalNumber" />=0A> <termCompList type=3D"lemma">=0A= > <termComp />=0A> </termCompList>=0A> = <termCompList type=3D"morphologicalElement">=0A> <termC= omp />=0A> </termCompList>=0A> <termNote type=3D"= termType">=0A> main </termNote>=0A> = <termNote type=3D"usageNote" />=0A> </termGrp>=0A> = <adminGrp>=0A> <admin type=3D"source">=0A> CS G= lossar </admin>=0A> <note />=0A> </adm= inGrp>=0A> <descripGrp>=0A> <descrip type=3D"exampl= e" />=0A> <adminGrp>=0A> <admin type=3D"source"= />=0A> </adminGrp>=0A> </descripGrp>=0A> = <note />=0A> </ntig>=0A> <ntig>=0A> <termGrp= >=0A> <term />=0A> <termNote type=3D"termType">= =0A> abbr </termNote>=0A> </termGrp>= =0A> <adminGrp>=0A> <admin type=3D"source" />=0A> = </adminGrp>=0A> </ntig>=0A> <ntig>=0A> = <termGrp>=0A> <term />=0A> <termNote type=3D"t= ermType">=0A> syn </termNote>=0A> = <termNote type=3D"grammaticalGender" />=0A> <termCompList type= =3D"lemma">=0A> <termComp />=0A> </termCompList= >=0A> <termCompList type=3D"morphologicalElement">=0A> = <termComp />=0A> </termCompList>=0A> </term= Grp>=0A> <adminGrp>=0A> <admin type=3D"source" />= =0A> <note />=0A> </adminGrp>=0A> <descr= ip type=3D"example" />=0A> <adminGrp>=0A> <admin ty= pe=3D"source" />=0A> </adminGrp>=0A> <note />=0A> = </ntig>=0A> </langSet>=0A> </termEntry>=0A> </body>=0A= > </text>=0A> </martif>=0A> =0A> _________________________________________= _________=0A> Do You Yahoo!?=0A> Tired of spam? Yahoo! Mail has the best s= pam protection around=0A> http://mail.yahoo.com=0A=0A______________________= ____________________________=0ADo You Yahoo!?=0ATired of spam? Yahoo! Mail= has the best spam protection around =0Ahttp://mail.yahoo.com