Hi, I optimized the predicate evaluation for this case; but only when using the short-hand form "[n]". The following will now stop at the first "item" element which satisfies [EMAIL PROTECTED] = '1']:
"/base/group/descendant::[EMAIL PROTECTED]'2' and parent::instances/parent::[EMAIL PROTECTED]'1']][1]" Use xpath.c revision 1.136. Regards, Kasimier > -----Original Message----- > From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On > Behalf Of Buchcik, Kasimier > Sent: Thursday, June 01, 2006 7:57 PM > To: Buchcik, Kasimier > Cc: [email protected] > Subject: RE: [xml] XPath / LibXML question > > Hi, > > > -----Original Message----- > > From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On > > Behalf Of Buchcik, Kasimier > > > -----Original Message----- > > > From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] > > > Sent: Thursday, June 01, 2006 5:18 PM > > > To: Buchcik, Kasimier > > > Cc: Aron Stansvik; Buchcik, Kasimier; [email protected] > > > Subject: RE: [xml] XPath / LibXML question > > > > > > Well, that certainly returns just the one result correctly... > > > > > > I take it from your comments about it not being optimized > > that it will > > > still find all results before returning the first, rather > than just > > > terminating at the first match? > > > > Although it will return just one node, it will still try to > apply the > > predicate "[EMAIL PROTECTED]'2' and > parent::instances/parent::[EMAIL PROTECTED]'1']]" > > on all "instance" elements it finds in the document. So > > actually it will > > run even slower than your original expression. I'll try to optimize > > this. > > > > But the expression I proposed (even if optimized) has the > > drawback that > > it won't be as efficient as a plain chain of node-tests in the child > > axis, > > if you *don't* know if the document will be of the expected > structure. > > Hmm, don't know if I expressed this understandable enough; I > > think this > > will become clearer if we assume that the given document has > > a document > > element with the name "foo"; here my expression will still > search the > > whole tree for "instance" elements, while your expression would stop > > already at the document element. So it all depends on how > much you can > > assume about the queried tree. > > [...] > > Apparently I haven't thought the issue to the end. Of course there's > also a way to restrict this to be an element inside /base/group: > > "/base/group/descendant::[EMAIL PROTECTED]'2' and > parent::instances/parent::[EMAIL PROTECTED]'1']][1]" > > Regards, > > Kasimier > _______________________________________________ > xml mailing list, project page http://xmlsoft.org/ > [email protected] > http://mail.gnome.org/mailman/listinfo/xml > > _______________________________________________ xml mailing list, project page http://xmlsoft.org/ [email protected] http://mail.gnome.org/mailman/listinfo/xml
