RE: how to prune subtrees in an XQuery result

Thank you Mike..

Regards,
Mukul

--- Michael Kay <mhk@mhk.me.uk> wrote:

> I'm hoping to do some XSLT vs XQuery performance
> comparisons over a wider
> range of queries over the next few weeks. I don't
> think you can draw too
> many conclusions from one example. However, I think
> that queries of the kind
> "copy the whole tree except for X" are more natural
> to express in XSLT than
> in XQuery and it wouldn't be surprising if such
> queries also performed
> better in XSLT. There are other queries (the more
> SQL-like queries) that are
> more natural to express in XQuery.
> 
> Obviously you can't extrapolate any performance
> results from Saxon and
> assume that they are characteristic of the two
> languages. That requires a
> wider set of comparisons.
> 
> I suspect most people will choose between the two
> languages based on
> perceived usability rather than performance.
> Perceived usability depends
> largely (in my view) on what other languages you
> have used before.
> 
> Michael Kay 
> 
> > -----Original Message-----
> > From: www-ql-request@w3.org
> [mailto:www-ql-request@w3.org] On 
> > Behalf Of Mukul Gandhi
> > Sent: 21 March 2005 08:06
> > To: Michael Kay; www-ql@w3.org
> > Subject: RE: how to prune subtrees in an XQuery
> result
> > 
> > 
> > Hi Mike,
> >   I did a performance comparison between XQuery
> > solution and the XSLT (1.0) solution (using Saxon
> 8.3;
> > with -t option).
> > 
> > The equivalent XSLT solution is(I guess it can be
> > written more efficiently):
> > 
> > <?xml version="1.0"?> 
> > <xsl:stylesheet
> > xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
> > version="1.0">
> >  
> >  <xsl:output method="xml" indent="yes" /> 
> >  
> >  <xsl:template match="/ASet">
> >    <Results>
> >      <xsl:for-each select="A">
> >        <xsl:if test="B[(. = 'red') or (. =
> 'yellow')]
> > or C[(. = 'chair') or (. = 'table')]">
> >          <A>
> >            <xsl:copy-of select="@*" />
> >            <xsl:copy-of select="B[(. = 'red') or
> (. =
> > 'yellow')] | C[(. = 'chair') or (. = 'table')]" />
> >          </A>
> >        </xsl:if>
> >      </xsl:for-each>
> >    </Results>
> >  </xsl:template>
> >  
> > </xsl:stylesheet>
> > 
> > XQuery solution's (average) execution time is -
> 313
> > milliseconds
> > XSLT solution's (average) execution time is - 63
> > milliseconds
> > 
> > XSLT seems quite faster than XQuery. Can we
> conclude
> > that XSLT will always be faster than XQuery? 
> > 
> > I believe XQuery is geared more towards database
> > rather than flat XML files.. Should we still
> prefer
> > XQuery sometimes than XSLT (when doing a normal
> flat
> > file XML transformation). 
> > 
> > Regards,
> > Mukul
> > 
> > --- Michael Kay <mhk@mhk.me.uk> wrote:
> > > Here's a solution that doesn't involve doing the
> > > comparisons twice.
> > > 
> > > <Results> {
> > >    for $A in doc("data.xml")/ASet/A
> > >    let $matches := $A/(B[.=("red","yellow")]
> > >                      |C[.=("chair","table")])
> > >    where ($matches)
> > >    return <A>{$matches}</A>
> > > }</Results>
> > > 
> > > Michael Kay
> > > http://www.saxonica.com/
> > > 
> > > > 
> > > > Hi Sergio,
> > > >   Probably this XQuery is required..
> > > > 
> > > > <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 
> > > >       <A>        
> > > >         {$A/@*}
> > > >         {$A/B[(. = 'red') or (. = 'yellow')]}
> > > >         {$A/C[(. = 'chair') or (. = 'table')]}
> > > >       </A>
> > > > }
> > > > </Results>
> > > > 
> > > > Regards,
> > > > Mukul
> > > > 
> > > > --- Sergio Andreozzi
> > > <sergio.andreozzi@cnaf.infn.it>
> > > > wrote:
> > > > > 
> > > > > 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
> > > > 
> > > > 
> > > > 
> > > > 		
> > > > __________________________________ 
> > > > Do you Yahoo!? 
> > > > Yahoo! Small Business - Try our new resources
> > > site!
> > > > http://smallbusiness.yahoo.com/resources/ 
> > > > 
> > > > 
> > > 
> > > 
> > > 
> > 
> > 
> > 		
> > __________________________________ 
> > Do you Yahoo!? 
> > Make Yahoo! your home page 
> > http://www.yahoo.com/r/hs
> > 
> > 
> 
> 
> 



		
__________________________________ 
Do you Yahoo!? 
Yahoo! Small Business - Try our new resources site!
http://smallbusiness.yahoo.com/resources/ 

Received on Monday, 21 March 2005 09:07:08 UTC