- From: Mukul Gandhi <mukul_gandhi@yahoo.com>
- Date: Mon, 21 Mar 2005 00:05:41 -0800 (PST)
- To: Michael Kay <mhk@mhk.me.uk>, www-ql@w3.org
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
Received on Monday, 21 March 2005 08:06:13 UTC