[XQuery Talk Mailing List Archive Home] [By Date] [By Thread] [By Subject] [By Author] [Recent Entries] [Reply To This Message]

outer for

Eric Robinson tracknerd2003 at yahoo.com
Thu Apr 23 12:11:05 PDT 2009


  outer for
Thanks for replying. 
 
The solution worked for what I am trying to do.
The predicate I gave you was just an example I was trying to come up with to make the where a little more complicated and cover all the conditions I was having issues with.


--- On Thu, 4/23/09, Michael Kay <http://x-query.com/mailman/listinfo/talk> wrote:

From: Michael Kay <http://x-query.com/mailman/listinfo/talk>
Subject: RE:  outer for
To: http://x-query.com/mailman/listinfo/talk, http://x-query.com/mailman/listinfo/talk
Date: Thursday, April 23, 2009, 1:30 PM



You're approaching this with a SQL mindset, and in my view that's not the right place to start - we're dealing here with hierarchies rather than tables.
 
I think it's often best to forget FLWOR expressions for this kind of thing and go back to basic XPath, because XPath is more natural to the hierarchical structure of XML. Keep FLWOR expressions for when you need to do real joins using value-based relationships.
 
I'm having a little trouble working out what your query is intended to mean. The predicate:
 
(($figure/title='Examples' or $section/title='Syntax) or ($figure/title='Examples' and $figure/image/@source='example.gif')))
 
has the form 
 
(A or B) or (A and C)
 
which is equivalent to
 
(A or B)
 
But let's imagine that the second test on $figure/title was looking for 'Examples2', I would then write the query as
 
 
book[author='Dan Suciu'][section/title='Syntax' or section/figure/title='Examples' or section/figure[title='Examples2' and image/@source='example.gif']]
 
No need for XQuery here - XPath 1.0 is quite sufficient.
 
Michael Kay
http://www.saxonica.com/




From: http://x-query.com/mailman/listinfo/talk [mailto:http://x-query.com/mailman/listinfo/talk] On Behalf Of Eric Robinson
Sent: 23 April 2009 17:50
To: http://x-query.com/mailman/listinfo/talk
Subject:  outer for







I was wondering if someone can help me with a xquery issue I am having.
 
What I am trying to do is create a web page that will allow a user to enter information about what they are looking for in a xml document and return to them the xml document if it matches their criteria. I thought I had it all working till I hit an issue with missing repeatable complex types.
 
Example of xml and xquery that works.
 
<book>
  <title>Data on the web</title>
  <author>Dan Suciu</author>
  <section>
    <title>Introduction</title>
    <figure>
      <title>Traditional</title>
      <image source="csarch.gih"/>
    </figure>
    <figure>
      <title>Examples</title>
      <image source="example.gif"/>
    </figure>
  </section>
  <section>
    <title>Syntax</title>
  </section>
</book>
 
for $book in /book
for $section in $book/section
for $figure in $section/figure
where ($book/author='Dan Suciu' and (($figure/title='Examples' and $section/title='Syntax) or ($figure/title='Examples' and $figure/image/@source='example.gif')))
return $book
 
Since the xml matches the where at 
<figure>
      <title>Examples</title>
      <image source="example.gif"/>
</figure>
it returns me the enitre document like I want.
 
Example that breaks my xquery.
 
<book>
<title>Data on the web</title>
  <author>Dan Suciu</author>
  <section>
    <title>Introduction</title>
   </section>
  <section>
    <title>Syntax</title>
  </section>
</book>
 
for $book in /book
for $section in $book/section
for $figure in $section/figure
where ($book/author='Dan Suciu' and (($figure/title='Examples' or $section/title='Syntax) or ($figure/title='Examples' and $figure/image/@source='example.gif')))
return $book
 
This will always return nothing because there is no /book/section/figure in the xml.
 
I believe once "outer for" is implemented I will be able to do 
 
for $book in /book
for $section in $book/section
outer for $figure in $section/figure
where ($book/author='Dan Suciu' and (($figure/title='Examples' or $section/title='Syntax) or ($figure/title='Examples' and $figure/image/@source='example.gif')))
return $book
 
 
Anyone have any ideas how I could get this to work?
 
 
 
 
_______________________________________________
http://x-query.com/mailman/listinfo/talk
http://x-query.com/mailman/listinfo/talk


      
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://x-query.com/pipermail/talk/attachments/20090423/954f2818/attachment.htm


PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2007 All Rights Reserved.