> XPath 1.0 only seems to be able to return an element and ALL of its > children. Does XPath 2.0 allow to write an expression that returns an > element and SOME of its children? This list isn't really intended for such questions: it's designed for comments on the spec, not for getting help and advice. You are wrong about XPath 1.0: the expression publisher[book[contains(@title, 'XML')]] | publisher/book[contains(@title, 'XML')] returns a node-set containing the required books together with their publishers. In XPath 2.0 you can express this more concisely as: publisher/book[contains(@title, 'XML')]/(.|..) However, your example shows that this isn't really what you want. > > Example: > > <publisher name="Addison Wesley"> > <book title="... XML .."/> > <book title="... Eiffel ..."/> > <book title="... XML ..."/> > </publisher> > <publisher name="O'Reilly"> > <book title="... XML ..."/> > <book title="... Java ..."/> > </publisher> > > I want to get all books where XML appears in the title, but I want to > know the publisher as well. This is the result I want to see: > > <publisher name="Addison Wesley"> > <book title="... XML .."/> > <book title="... XML ..."/> > </publisher> > <publisher name="O'Reilly"> > <book title="... XML ..."/> > </publisher> > Neither XPath 1.0 nor XPath 2.0 can construct this result. XPath only selects nodes in an existing tree. To construct a new tree, by selectively copying nodes from an existing tree, you need XSLT or XQuery. Michael KayReceived on Wednesday, 3 July 2002 12:31:29 GMT
This archive was generated by hypermail 2.2.0+W3C-0.50 : Tuesday, 8 January 2008 14:13:57 GMT