RE: Does XPath 2.0 allow me to return a node and a subset of its child nodes?

I would like to suggest that you send this kind of question to the
www-ql@w3.org list. 
 
Public-qt-comments@w3.org is meant for comments/issues on the
XQuery/XPath/XSLT specifications.  

It is more likely that you will get a timely answer to your question
using www-ql@w3.org.

/paulc
Chair, XML Query WG

Paul Cotton, Microsoft Canada 
17 Eleanor Drive, Nepean, Ontario K2E 6A3 
Tel: (613) 225-5445 Fax: (425) 936-7329 
<mailto:pcotton@microsoft.com> 


> -----Original Message-----
> From: Berend de Boer [mailto:berend@xsol.co.nz]
> Sent: Sunday, June 30, 2002 6:10 PM
> To: public-qt-comments@w3.org
> Subject: Does XPath 2.0 allow me to return a node and a subset of its
> child nodes?
> 
> 
> 
> 
> 
> Hello All,
> 
> 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?
> 
> 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>
> 
> 
> I've been unable to express this query with XPath 1.0.
> publisher[book/@title='XML'] returns publishers and ALL books, and
> publisher/book[@title='XML'] gives ONLY the books and does NOT have
the
> parent <publisher> (read for '=' contains()...).
> 
> 
> What I can understand from the specs, a for loop can do what I want.
But
> can anyone suggest what it would look like? This is probably
incorrect:
> 
> for $p in (//publisher)
> return (<publisher name="$p">,
>          for $b in //book[../@name=$p/@name]
>          return $b,
>          </publisher>)
> 
> 
> But more importantly, is there an expression that doesn't use
> programming? My XPath expressions are meant for non-programmers, and a
> for loop is probably not easy to understand for them.
> 
> In the use cases (1.2.4.1 Q1) I found something like this:
> 
> <result>
>    {
>      let $b := document("publishers.xml")
>      return
>          filter($b//publisher | $b//publisher/book[@title='XML'])
>    }
> </result>
> 
> 
> I really didn't understand this expression at all. I assume it's equal
> to [//publisher | //publisher/book[@title='XML'] but with XPath 1.0
this
> returns all publishers, including all their child elements, i.e. all
> books and not only the books with 'XML' in the title. Is XPath 2.0
> different in this respect? So does $b//publisher just return
publishers
> and not the child nodes??
> 
> To give you some background: for a certain XML database I'm
> investigating what language is most appropiate to use to specify
> queries. XPath 1.0 seemed to be limited in its power, but a full
> programming language is too much. So I'm searching for a relative
simple
> declarative query language, that isn't too hard to implement and can
run
> fast on a relational database (the XML is stored in a relational
> database). So I like to know if XPath 2.0 is more suited to the task.
> 
> 
> Any help appreciated.
> 
> Regards,
> 
> Berend. (-:
> 

Received on Wednesday, 3 July 2002 09:54:41 UTC