- From: Daniela Florescu <dana@xqrl.com>
- Date: 24 Feb 2002 21:41:51 -0800
- To: Chen Ya Bing <iscp0054@nus.edu.sg>
- Cc: Peter Fankhauser <fankhaus@ipsi.fhg.de>, www-ql@w3.org
Chen, Xquery has a function called filter that might be of some help for your problem. Here is what the filter function does (I cite from the Xquery document): ===================================== 4.1 Filtering One of the functions in the XQuery core function library is called filter. This function takes a single parameter which can be any expression. The function evaluates its argument and returns a shallow copy of the nodes that are selected by the argument, preserving any relationships that exist among these nodes. For example, suppose that the argument to filter is a path expression that selects nodes X, Y, and Z from some document. Suppose that, in the original document, nodes Y and Z are descendants (at any level) of node X. Then the result of filter is a copy of node X, with copies of nodes Y and Z as its immediate children. Any other intervening nodes from the original document are not present in the result. The name filter suggests a function that operates on a document to extract the parts that are of interest and discard the remainder, while retaining the structure of the original document. ========================================= A rewriting of your query using filter would be the following (if I understand your query correctly, of course): filter( for $x in //part[price>100] return ($x/descendant-or-self::node(), $x/.., $x/../..) ) Does this do the job you need ? Best regards, Dana On Sun, 2002-02-24 at 17:34, Chen Ya Bing wrote: > Messageone of the actual difficulties is like that: > > there is a XML document (spj.xml): > <db> > > <project jno="j001"> > > <supplier sno="s001"> > > <part pno="p001"> > > <price> 100</price> > > </part> > > </supplier> > > <supplier sno="s002"> > > <part pno="p001"> > > <price> 110</price> > > </part> > > </supplier> > > </project> > > </db> > > > > we want to define a view which selects such project, supplier and part that their sub element price is greater than 100. the view definition may be: > > > > define view test as > > For $j In document("spj.xml")//project[//price >100] > > Return > > <project jno = {$j/@jno}> > > { For $s In $j/supplier[//price >100] > > Return > > <supplier sno = {$s/@sno}> > > { For $p In $s/part[price > 100] > > Return > > <part pno = {$p/@pno}> > > {$p/price} > > </part> > > } > > </supplier> > > } > > </project> > > > > we can see that for such a simple view, we need to repeat the predicate "price >100" three times, which will lead to a very low performance of query processing, because we need to search the tree three times. the view definition is not only complex and wordy, but also low-performance. > > Is there any other way to write the query? > > > > as a view definition, one of favorite feature is that it is declarative, so that we don't need to write a very complex definition. > > > > can we just use a more simple way to write view, can XML Algebra provide any help? > > > > the view is just to put a predicate to filter some elements. if we define a view that change some structures, the view definition will be more complex. > > > > until now, we do not consider the problem of view updatability and the combination of XML-Schema and XQuery. > > > > Best regards, > > > > ----- Original Message ----- > From: Peter Fankhauser > To: 'Chen Ya Bing' ; www-ql@w3.org > Sent: Thursday, February 21, 2002 9:40 PM > Subject: RE: define views using xquery > > > As a starter from the scientific side you may check out > some recent papers by Serge Abiteboul and others (one of > Serge's favorite themes is views in all disguises). > > I'd be also be interested in the actual difficulties that you > encountered when trying views with XQuery. In principle > one can regard a view as a "stored" query which can be > composed with other queries. As one of XQuery's virtues > is compositionality, another is closure, so I wonder where exactly > the difficulty lies. > > (1) Is it the combination of XML-Schema and XQuery that > you (presumably) need. > > (2) Is it updatability of views that concern you? > > (3) Is it that your notion of "simple view" doesn't translate > to an XQuery notion of a "simple query"? > > (4) Which sort of views do you want to define? > > Have you got any concrete examples, usecases, requirements? > Where exactly do you encounter inefficiency? > > Best regards, > > Peter > > > -----Original Message----- > From: www-ql-request@w3.org [mailto:www-ql-request@w3.org] On Behalf Of Chen Ya Bing > Sent: Donnerstag, 21. Februar 2002 10:02 > To: www-ql@w3.org > Subject: define views using xquery > > > I'd like to use XQuery as a view definition language to define XML views. but I find that it is difficult to use it as the view definition language, because a simple view definition have to lead to a complex XQuery. even more, it may be inefficient. comparing with view definition in SQL, it is inconvenient. > > can anybody give me advices of how to utilize XQuery to define XML view more efficiently? > and how will the XQuery WD support the view facility. > > Best regards, > Chen
Received on Monday, 25 February 2002 00:48:05 UTC