Re: Incorrect "No result for query" for XPath expression
Natalia Shilenkova <[email protected]> Wed, 21 Oct 2009 18:13:55 -0400
| Newsgroups | gmane.text.xml.xindice.user |
|---|---|
| Message-ID | <[email protected]> |
David, The problem you're describing is not a bug, your XPath query is =20 executed correctly. Let's see what happens when query /martif/text/body/termEntry[contains=20= (langSet/ntig/termGrp/term/text(),'bancaire')] is executed. First, =20 XPath finds all nodes with path /martif/text/body/termEntry/langSet/=20 ntig/termGrp/term and selects their children text nodes. The result of =20= this step is node-set, which includes <term> data for every language. =20= Then, XPath evaluates function contains(), where first argument is =20 node-set. Per XPath specification [1], function contains expects two =20 arguments of type string, not node-set, so it converts the first =20 argument to string using function string(). When applied to node-set, =20= it returns string value of the _first_ node in the document order. Instead of checking <term> data for every language, it just checks if =20= <term> data contains given string for language that happened to be =20 first in the document. You can easily verify that by rearranging order =20= of langSet tags in the document. The query /martif/text/body/termEntry=20= [contains(langSet[starts-with(@lang,'fr')]/ntig/termGrp/term/text=20 (),'bancaire')] works because of the same reason: contains() function =20= only gets one langSet. If you want the query that would check all the text nodes to see if =20 they contain some substring, you can try something like that: /martif/text/body/termEntry[langSet/ntig/termGrp/term[contains(text=20 (),'bancaire')]] [1] http://www.w3.org/TR/1999/REC-xpath-19991116 Regards, Natalia On Oct 21, 2009, at 12:02 PM, David Vergnaud wrote: > Hi, > > I'm reporting on a problem which I'm pretty much convinced is a bug =20= > in the current 1-2.dev version of Xindice (1.2m1). I'm using Xindice =20= > running on its own (no Tomcat) as a daemon on a Linux box (Suse 11) =20= > with JDK 1.6. > > Basically, I have a DB where I've stored terminology entries that =20 > contain information about various banking terms in 4 languages. I =20 > want to be able to conduct two types of searches, one where the term =20= > is searched for only one of the languages, and one where the search =20= > is carried out in all languages. For this, I use two versions of a =20 > somewhat complicated XPath expression: one where the language is =20 > specified (as attribute of one of the nodes, in a predicate) and one =20= > where it isn't. This is the only difference between the two =20 > expressions. Surprisingly, the one where the language is fixed does =20= > return results where the one without specification doesn't. Besides, =20= > I've tested the XPath expression on other systems, and seen that =20 > there really should be results. > > The first impression is that when evaluating function arguments =20 > inside a predicate, only the first node of a node set is evaluated. =20= > In my case, that would be confirmed by the following fact: each =20 > entry contains first the German word, then either French or English. =20= > When doing an "unrefined" search (no language specification) with a =20= > German word, results are returned. When doing the same unrefined =20 > search with French or English, no results are returned. > > Here's an example of an XPath we're using, first with the language =20 > refinement, then without: > /martif/text/body/termEntry[contains(langSet[starts-with=20 > (@lang,'fr')]/ntig/termGrp/term/text(),'bancaire')] > /martif/text/body/termEntry[contains(langSet/ntig/termGrp/term/text=20 > (),'bancaire')] > > As you can see, the goal is to extract a termEntry element which =20 > contains the word "bancaire" under the specified path. In the first =20= > path, I set the langSet to have attribute lang start with "fr" (for =20= > French), in the second I don't. As I said before, the first =20 > expression yields a result and the second one doesn't. > > I'm including an example DB entry which can be used to test this -- =20= > I assume it should be possible to observe this behaviour with only =20 > one entry in the DB as well. In order to use the xpath above with =20 > it, one would need to prefix all node names in the xpath expression =20= > with "tbx" (I only removed that for legibility). > > Should this prove to be an error on my side, I'd be grateful to =20 > anyone who'd point it out. Otherwise, it might need to be taken onto =20= > the Xindice bug list. > > Cheers, > > David > > <?xml version=3D"1.0"?> > <martif xmlns=3D"http://www.lisa.org/tbx" type=3D"TBX" = xml:lang=3D"de-CH"> > <martifHeader> > <fileDesc> > <titleStmt> > <title> > Test-TerminologieDB </title> > </titleStmt> > <publicationStmt> > <p> > Version 1.1 </p> > </publicationStmt> > <sourceDesc> > <p> > Version 1.1 </p> > </sourceDesc> > </fileDesc> > </martifHeader> > <text> > <body> > <termEntry> > <descrip type=3D"classificationCode" /> > <descrip type=3D"subjectField"> > </descrip> > <langSet xml:lang=3D"de-CH"> > <transacGrp> > <transac type=3D"transactionType"> > created </transac> > <transacNote type=3D"responsibility"> > STEA </transacNote> > <date> > 2009-09-15T14:44:54.924+02:00 </date> > </transacGrp> > <descrip type=3D"reliabilityCode"> > 1 </descrip> > <note /> > <descripGrp> > <descrip type=3D"definition"> > Die Garantie ist eine selbstst=E4ndige, vom =20 > Hauptschuldverh=E4ltnis unabh=E4ngige Verpflichtung. Der Garant (die =20= > Bank) kann keinerlei Einwendungen und Einreden aus dem Grundgesch=E4ft = =20 > erheben. Das heisst: Der Garant zahlt auf erste schriftliche =20 > Anforderung (Inanspruchnahme) des Beg=FCnstigten, gegen Einreichung =20= > der im Garantietext vorgeschriebenen Best=E4tigung und allenfalls =20 > vorgeschriebenen Dokumente. </descrip> > <adminGrp> > <admin type=3D"source"> > CS Glossar </admin> > </adminGrp> > </descripGrp> > <ntig> > <termGrp> > <term> > Bankgarantie </term> > <termNote type=3D"partOfSpeech" /> > <termNote type=3D"grammaticalGender" /> > <termNote type=3D"grammaticalNumber" /> > <termCompList type=3D"lemma"> > <termComp /> > </termCompList> > <termCompList type=3D"morphologicalElement"> > <termComp /> > </termCompList> > <termNote type=3D"termType"> > main </termNote> > <termNote type=3D"usageNote" /> > </termGrp> > <adminGrp> > <admin type=3D"source"> > CS Glossar </admin> > <note /> > </adminGrp> > <descripGrp> > <descrip type=3D"example" /> > <adminGrp> > <admin type=3D"source" /> > </adminGrp> > </descripGrp> > <note /> > </ntig> > <ntig> > <termGrp> > <term /> > <termNote type=3D"termType"> > abbr </termNote> > </termGrp> > <adminGrp> > <admin type=3D"source" /> > </adminGrp> > </ntig> > <ntig> > <termGrp> > <term /> > <termNote type=3D"termType"> > syn </termNote> > <termNote type=3D"grammaticalGender" /> > <termCompList type=3D"lemma"> > <termComp /> > </termCompList> > <termCompList type=3D"morphologicalElement"> > <termComp /> > </termCompList> > </termGrp> > <adminGrp> > <admin type=3D"source" /> > <note /> > </adminGrp> > <descrip type=3D"example" /> > <adminGrp> > <admin type=3D"source" /> > </adminGrp> > <note /> > </ntig> > </langSet> > <langSet xml:lang=3D"en-GB"> > <transacGrp> > <transac type=3D"transactionType"> > created </transac> > <transacNote type=3D"responsibility"> > STEA </transacNote> > <date> > 2009-09-15T14:44:54.924+02:00 </date> > </transacGrp> > <descrip type=3D"reliabilityCode"> > 1 </descrip> > <note /> > <descripGrp> > <descrip type=3D"definition" /> > <adminGrp> > <admin type=3D"source" /> > </adminGrp> > </descripGrp> > <ntig> > <termGrp> > <term> > bank guarantee </term> > <termNote type=3D"partOfSpeech" /> > <termNote type=3D"grammaticalGender" /> > <termNote type=3D"grammaticalNumber" /> > <termCompList type=3D"lemma"> > <termComp /> > </termCompList> > <termCompList type=3D"morphologicalElement"> > <termComp /> > </termCompList> > <termNote type=3D"termType"> > main </termNote> > <termNote type=3D"usageNote" /> > </termGrp> > <adminGrp> > <admin type=3D"source"> > CS Glossar </admin> > <note /> > </adminGrp> > <descripGrp> > <descrip type=3D"example" /> > <adminGrp> > <admin type=3D"source" /> > </adminGrp> > </descripGrp> > <note /> > </ntig> > <ntig> > <termGrp> > <term /> > <termNote type=3D"termType"> > abbr </termNote> > </termGrp> > <adminGrp> > <admin type=3D"source" /> > </adminGrp> > </ntig> > <ntig> > <termGrp> > <term /> > <termNote type=3D"termType"> > syn </termNote> > <termNote type=3D"grammaticalGender" /> > <termCompList type=3D"lemma"> > <termComp /> > </termCompList> > <termCompList type=3D"morphologicalElement"> > <termComp /> > </termCompList> > </termGrp> > <adminGrp> > <admin type=3D"source" /> > <note /> > </adminGrp> > <descrip type=3D"example" /> > <adminGrp> > <admin type=3D"source" /> > </adminGrp> > <note /> > </ntig> > </langSet> > <langSet xml:lang=3D"fr-CH"> > <transacGrp> > <transac type=3D"transactionType"> > created </transac> > <transacNote type=3D"responsibility"> > STEA </transacNote> > <date> > 2009-09-15T14:44:54.924+02:00 </date> > </transacGrp> > <descrip type=3D"reliabilityCode"> > 1 </descrip> > <note /> > <descripGrp> > <descrip type=3D"definition" /> > <adminGrp> > <admin type=3D"source" /> > </adminGrp> > </descripGrp> > <ntig> > <termGrp> > <term> > garantie bancaire </term> > <termNote type=3D"partOfSpeech" /> > <termNote type=3D"grammaticalGender" /> > <termNote type=3D"grammaticalNumber" /> > <termCompList type=3D"lemma"> > <termComp /> > </termCompList> > <termCompList type=3D"morphologicalElement"> > <termComp /> > </termCompList> > <termNote type=3D"termType"> > main </termNote> > <termNote type=3D"usageNote" /> > </termGrp> > <adminGrp> > <admin type=3D"source"> > CS Glossar </admin> > <note /> > </adminGrp> > <descripGrp> > <descrip type=3D"example" /> > <adminGrp> > <admin type=3D"source" /> > </adminGrp> > </descripGrp> > <note /> > </ntig> > <ntig> > <termGrp> > <term /> > <termNote type=3D"termType"> > abbr </termNote> > </termGrp> > <adminGrp> > <admin type=3D"source" /> > </adminGrp> > </ntig> > <ntig> > <termGrp> > <term /> > <termNote type=3D"termType"> > syn </termNote> > <termNote type=3D"grammaticalGender" /> > <termCompList type=3D"lemma"> > <termComp /> > </termCompList> > <termCompList type=3D"morphologicalElement"> > <termComp /> > </termCompList> > </termGrp> > <adminGrp> > <admin type=3D"source" /> > <note /> > </adminGrp> > <descrip type=3D"example" /> > <adminGrp> > <admin type=3D"source" /> > </adminGrp> > <note /> > </ntig> > </langSet> > <langSet xml:lang=3D"it-CH"> > <transacGrp> > <transac type=3D"transactionType"> > created </transac> > <transacNote type=3D"responsibility"> > STEA </transacNote> > <date> > 2009-09-15T14:44:54.924+02:00 </date> > </transacGrp> > <descrip type=3D"reliabilityCode"> > 1 </descrip> > <note /> > <descripGrp> > <descrip type=3D"definition" /> > <adminGrp> > <admin type=3D"source" /> > </adminGrp> > </descripGrp> > <ntig> > <termGrp> > <term> > garanzia bancaria </term> > <termNote type=3D"partOfSpeech" /> > <termNote type=3D"grammaticalGender" /> > <termNote type=3D"grammaticalNumber" /> > <termCompList type=3D"lemma"> > <termComp /> > </termCompList> > <termCompList type=3D"morphologicalElement"> > <termComp /> > </termCompList> > <termNote type=3D"termType"> > main </termNote> > <termNote type=3D"usageNote" /> > </termGrp> > <adminGrp> > <admin type=3D"source"> > CS Glossar </admin> > <note /> > </adminGrp> > <descripGrp> > <descrip type=3D"example" /> > <adminGrp> > <admin type=3D"source" /> > </adminGrp> > </descripGrp> > <note /> > </ntig> > <ntig> > <termGrp> > <term /> > <termNote type=3D"termType"> > abbr </termNote> > </termGrp> > <adminGrp> > <admin type=3D"source" /> > </adminGrp> > </ntig> > <ntig> > <termGrp> > <term /> > <termNote type=3D"termType"> > syn </termNote> > <termNote type=3D"grammaticalGender" /> > <termCompList type=3D"lemma"> > <termComp /> > </termCompList> > <termCompList type=3D"morphologicalElement"> > <termComp /> > </termCompList> > </termGrp> > <adminGrp> > <admin type=3D"source" /> > <note /> > </adminGrp> > <descrip type=3D"example" /> > <adminGrp> > <admin type=3D"source" /> > </adminGrp> > <note /> > </ntig> > </langSet> > </termEntry> > </body> > </text> > </martif> > > __________________________________________________ > Do You Yahoo!? > Tired of spam? Yahoo! Mail has the best spam protection around > http://mail.yahoo.com