|
[XQuery Talk Mailing List Archive Home] [By Date] [By Thread] [By Subject] [By Author] [Recent Entries] [Reply To This Message] outer forMichael Kay mike at saxonica.comThu Apr 23 19:30:45 PDT 2009
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? -------------- next part -------------- An HTML attachment was scrubbed... URL: http://x-query.com/pipermail/talk/attachments/20090423/dfcbf7ab/attachment-0001.htm
|
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
|






