W3C home > Mailing lists > Public > www-ql@w3.org > January to March 2005

how to prune subtrees in an XQuery result

From: Sergio Andreozzi <sergio.andreozzi@cnaf.infn.it>
Date: Sun, 20 Mar 2005 04:17:44 +0100
Message-ID: <423CEB58.6010700@cnaf.infn.it>
To: www-ql@w3.org

Dear all,

I'm wondering what is the best way to prune subtrees that did not match 
the where clause of a FLOWER expression.  See the example below for 
clarification:

SAMPLE DATA

<ASet>
	<A name="one">
		<B>red</B>
		<B>yellow</B>
		<B>green</B>
		<C>chair</C>
		<C>table</C>
		<C>sofa</C>
	</A>
	<A name="two">
		<B>red</B>
		<B>green</B>
		<C>chair</C>
		<C>sofa</C>
	</A>
	<A name="three">
		<B>green</B>
		<C>chair</C>
		<C>table</C>
		<C>sofa</C>
	</A>
</ASet>

QUERY: for each A, list all the name of A, their B elements that are 
either "red" or "yellow" and their C elements that are either "chair" or 
"table"

EXPECTED RESULT:

<Results>
	<A name="one">
		<B>red</B>
		<B>yellow</B>
		<C>chair</C>
		<C>table</C>
	</A>
	<A name="two">
		<B>red</B>
		<C>chair</C>
	</A>
</Results>


in practice what I would like to understand is how to prune all the 
subtrees that do not contain any match with components of the WHERE 
clause in the XQuery result.

The general pruning rule is "if an element does not participate in the 
satisfaction of the WHERE clause and all its children elements (if any) 
don't participate as well, then prune it from the result".

A possible starting point is the following query, but the pruning action 
is missing.

<Results>
{
      for $A in doc("data.xml")/ASet/A
      where ($A/B = "red" or $A/B = "yellow")
            and ($A/C = "chair" or $A/C = "table")
      return ...
}
</Results>



Thanks,

	Sergio
Received on Sunday, 20 March 2005 03:23:34 UTC

This archive was generated by hypermail 2.3.1 : Tuesday, 6 January 2015 20:17:16 UTC