<table cellspacing="0" cellpadding="0" border="0" ><tr><td valign="top" style="font: inherit;"><DIV>Thanks for replying. </DIV>
<DIV> </DIV>
<DIV>The solution worked for what I am trying to do.</DIV>
<DIV>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.</DIV>
<DIV><BR><BR>--- On <B>Thu, 4/23/09, Michael Kay <I><mike@saxonica.com></I></B> wrote:<BR></DIV>
<BLOCKQUOTE style="PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: rgb(16,16,255) 2px solid">From: Michael Kay <mike@saxonica.com><BR>Subject: RE: [xquery-talk] outer for<BR>To: tracknerd2003@yahoo.com, talk@x-query.com<BR>Date: Thursday, April 23, 2009, 1:30 PM<BR><BR>
<DIV id=yiv951930097>
<DIV dir=ltr align=left><SPAN class=175041917-23042009><FONT face=Arial color=#0000ff size=2>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.</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=175041917-23042009><FONT face=Arial color=#0000ff size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=175041917-23042009><FONT face=Arial color=#0000ff size=2>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.</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=175041917-23042009><FONT face=Arial color=#0000ff size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=175041917-23042009><FONT face=Arial color=#0000ff size=2>I'm having a little trouble working out what your query is intended to mean. The predicate:</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=175041917-23042009><FONT face=Arial color=#0000ff size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=175041917-23042009><FONT color=#0000ff><FONT color=#000000>(($figure/title='Examples' or $section/title='Syntax) or ($figure/title='Examples' and </FONT><A href="mailto:$figure/image/@source='example.gif'" target=_blank rel=nofollow>$figure/image/@source='example.gif'</A><FONT color=#000000>)))</FONT></FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=175041917-23042009></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=175041917-23042009><FONT face=Arial color=#0000ff size=2>has the form </FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=175041917-23042009><FONT face=Arial color=#0000ff size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=175041917-23042009><FONT face=Arial color=#0000ff size=2>(A or B) or (A and C)</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=175041917-23042009><FONT face=Arial color=#0000ff size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=175041917-23042009><FONT face=Arial color=#0000ff size=2>which is equivalent to</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=175041917-23042009><FONT face=Arial color=#0000ff size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=175041917-23042009><FONT face=Arial color=#0000ff size=2>(A or B)</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=175041917-23042009><FONT face=Arial color=#0000ff size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=175041917-23042009><FONT face=Arial color=#0000ff size=2>But let's imagine that the second test on $figure/title was looking for 'Examples2', I would then write the query as</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=175041917-23042009><FONT face=Arial color=#0000ff size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=175041917-23042009><FONT face=Arial color=#0000ff size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=175041917-23042009><FONT face=Arial color=#0000ff size=2>book[author='Dan Suciu'][section/title='Syntax' or section/figure/title='Examples' or section/figure[title='Examples2' and <A href="mailto:image/@source='example.gif'" target=_blank rel=nofollow>image/@source='example.gif'</A>]]</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=175041917-23042009><FONT face=Arial color=#0000ff size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=175041917-23042009><FONT face=Arial color=#0000ff size=2>No need for XQuery here - XPath 1.0 is quite sufficient.</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=175041917-23042009><FONT face=Arial color=#0000ff size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=175041917-23042009><FONT face=Arial color=#0000ff size=2>Michael Kay</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=175041917-23042009><FONT face=Arial color=#0000ff size=2><A href="http://www.saxonica.com/" target=_blank rel=nofollow>http://www.saxonica.com/</A></FONT></SPAN></DIV><BR>
<BLOCKQUOTE style="PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #0000ff 2px solid; MARGIN-RIGHT: 0px">
<DIV class=OutlookMessageHeader lang=en-us dir=ltr align=left>
<HR tabIndex=-1>
<FONT face=Tahoma size=2><B>From:</B> talk-bounces@x-query.com [mailto:talk-bounces@x-query.com] <B>On Behalf Of </B>Eric Robinson<BR><B>Sent:</B> 23 April 2009 17:50<BR><B>To:</B> talk@x-query.com<BR><B>Subject:</B> [xquery-talk] outer for<BR></FONT><BR></DIV>
<DIV></DIV>
<TABLE cellSpacing=0 cellPadding=0 border=0>
<TBODY>
<TR>
<TD vAlign=top>
<DIV>I was wondering if someone can help me with a xquery issue I am having.</DIV>
<DIV> </DIV>
<DIV>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.</DIV>
<DIV> </DIV>
<DIV>Example of xml and xquery that works.</DIV>
<DIV> </DIV>
<DIV><book></DIV>
<DIV> <title>Data on the web</title></DIV>
<DIV> <author>Dan Suciu</author></DIV>
<DIV> <section></DIV>
<DIV> <title>Introduction</title></DIV>
<DIV> <figure></DIV>
<DIV> <title>Traditional</title></DIV>
<DIV> <image source="csarch.gih"/></DIV>
<DIV> </figure></DIV>
<DIV> <figure></DIV>
<DIV> <title>Examples</title></DIV>
<DIV> <image source="example.gif"/></DIV>
<DIV> </figure></DIV>
<DIV> </section></DIV>
<DIV> <section></DIV>
<DIV> <title>Syntax</title></DIV>
<DIV> </section></DIV>
<DIV></book></DIV>
<DIV> </DIV>
<DIV>for $book in /book</DIV>
<DIV>for $section in $book/section</DIV>
<DIV>for $figure in $section/figure</DIV>
<DIV>where ($book/author='Dan Suciu' and (($figure/title='Examples' and $section/title='Syntax) or ($figure/title='Examples' and <A href="mailto:$figure/image/@source='example.gif'" target=_blank rel=nofollow>$figure/image/@source='example.gif'</A>)))</DIV>
<DIV>return $book</DIV>
<DIV> </DIV>
<DIV>Since the xml matches the where at </DIV>
<DIV><figure></DIV>
<DIV> <title>Examples</title></DIV>
<DIV> <image source="example.gif"/></DIV>
<DIV></figure></DIV>
<DIV>it returns me the enitre document like I want.</DIV>
<DIV> </DIV>
<DIV>Example that breaks my xquery.</DIV>
<DIV> </DIV>
<DIV><book></DIV>
<DIV><title>Data on the web</title></DIV>
<DIV> <author>Dan Suciu</author></DIV>
<DIV> <section></DIV>
<DIV> <title>Introduction</title></DIV>
<DIV> </section></DIV>
<DIV> <section></DIV>
<DIV> <title>Syntax</title></DIV>
<DIV> </section></DIV>
<DIV></book></DIV>
<DIV> </DIV>
<DIV>for $book in /book</DIV>
<DIV>for $section in $book/section</DIV>
<DIV>for $figure in $section/figure</DIV>
<DIV>where ($book/author='Dan Suciu' and (($figure/title='Examples' or $section/title='Syntax) or ($figure/title='Examples' and <A href="mailto:$figure/image/@source='example.gif'" target=_blank rel=nofollow>$figure/image/@source='example.gif'</A>)))</DIV>
<DIV>return $book</DIV>
<DIV> </DIV>
<DIV>This will always return nothing because there is no /book/section/figure in the xml.</DIV>
<DIV> </DIV>
<DIV>I believe once "outer for" is implemented I will be able to do </DIV>
<DIV> </DIV>
<DIV>for $book in /book</DIV>
<DIV>for $section in $book/section</DIV>
<DIV>outer for $figure in $section/figure</DIV>
<DIV>where ($book/author='Dan Suciu' and (($figure/title='Examples' or $section/title='Syntax) or ($figure/title='Examples' and <A href="mailto:$figure/image/@source='example.gif'" target=_blank rel=nofollow>$figure/image/@source='example.gif'</A>)))</DIV>
<DIV>return $book</DIV>
<DIV> </DIV>
<DIV> </DIV>
<DIV>Anyone have any ideas how I could get this to work?</DIV>
<DIV> </DIV>
<DIV> </DIV>
<DIV> </DIV>
<DIV> </DIV></TD></TR></TBODY></TABLE><BR></BLOCKQUOTE></DIV><PRE>_______________________________________________
talk@x-query.com
http://x-query.com/mailman/listinfo/talk</PRE></BLOCKQUOTE></td></tr></table><br>