joining multiple queries into a single oneMichael Kay mhk at mhk.me.uk
Wed Apr 12 00:06:06 PDT 2006
Firstly, a query does not have to be a FLWOR expression! This: for $r in //task where $r/prolog/meta/filename/text()="xys" return $r is just a rather long-winded way of writing //task[prolog/meta/filename/text()="xys"] Secondly, that "/text()" at the end of the path expression is really bad practice. Unfortunately it's sometimes used by people who ought to know better. There are several good reasons to avoid it: (a) it causes the query to fail or produce wrong results if the source XML contains comments - queries should normally be written so they aren't affected by comments. (b) if the data is typed, you are throwing away the type information and possibly causing unnecessary data conversions. (c) It's just plain redundant: write //task[prolog/meta/filename = "xys"] Thirdly, the "task" seems to be the outermost element in your document. Use /task rather than //task to avoid a search of the whole document. [This might not apply to eXist: but it never does any harm to give the system more information to narrow the search.] Now to your question. If you don't care what the outermost element is called, use /*[prolog/meta/filename = "xys"] If you want to match an outermost element called "task" or "concept" but nothing else, use /(task|concept)[prolog/meta/filename = "xys"] Michael Kay http://www.saxonica.com/ > -----Original Message----- > From: http://xquery.com/mailman/listinfo/talk > [mailto:http://xquery.com/mailman/listinfo/talk] On Behalf Of Titash Neogi > Sent: 11 April 2006 11:08 > To: http://xquery.com/mailman/listinfo/talk > Subject: joining multiple queries into a single one > > Dear All, > > Please consider the following scenario. > > I have XML content in a database. These files are of four categories. > tasks, concepts, refs and topics. > > Task files are contained in <task> </task> > Concept files with <concept></concept> > And so on. > > Withing each file there is a metadata that can be used for querying. > This metadata is similar for all for types of files. > > <task> > <prolog> > <meta> > <filename>FILENAME A</filename> > <lang>ENG</lang> > <nature>SOME</nature> > <id>8990</id> > </meta> > </prolog> > ... > ... > ... > </task> > > > <concept> > <prolog> > <meta> > <filename>FILENAME B</filename> > <lang>HND</lang> > <nature>SOME</nature> > <id>82230</id> > </meta> > </prolog> > ... > ... > ... > </concept> > > And so on for other files. > > My problem is - > > I am trying to a write a query that can search and extract > content from > all these types of files. I know how to write a query for individual > file types but I want to write a single query for all four file types. > Here is an example - > > Currently my query looks something like this > > for $r in //task where $r/prolog/meta/filename/text()="xys" return $r > > for $r in //concept where > $r/prolog/meta/filename/text()="xys" return $r > > > I want to do away with this redundancy and write a single > query for this > which works on all four file types in the database. > > I am using the eXist Native XML Database. My content files > are the path > /db/content > > > If I write a query such as > > For $r in /db/content where $r//prolog/meta/filename/text()="xys" > > this doesn't seem to work. > > Please advice. > > Thanks and regards > Titash > > > _______________________________________________ > http://xquery.com/mailman/listinfo/talk > http://xquery.com/mailman/listinfo/talk >
PURCHASE STYLUS STUDIO ONLINE TODAY!
Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!
Download The World's Best XML IDE!
Accelerate XML development with our award-winning XML IDE - Download a free trial today!
Subscribe in XML format