XML Editor
Sign up for a WebBoard account Sign Up Keyword Search Search More Options... Options
Chat Rooms Chat Help Help News News Log in to WebBoard Log in Not Logged in
Show tree view Topic
Go to previous topicPrev TopicGo to next topicNext Topic
Postnext
Jim SalmonsSubject: Newbie struggling with nested FLWOR expression
Author: Jim Salmons
Date: 05 Sep 2007 08:33 PM
Originally Posted: 05 Sep 2007 08:30 PM
My source document is of ITEMS/ITEM where an ITEM has a collection of IMAGES with an IMAGE having a URL. From everything I read, it would appear that the following should work:

<root>
{
let $doc := .
for $ITEM in $doc/ITEMS/ITEM
return
<catnum>{$ITEM/CATNUM/text()}
</catnum>
{for $IMAGE in $doc/ITEMS/ITEM[CATNUM = $ITEM/CATNUM]/IMAGES/IMAGE
return
<url>
{$IMAGE/URL/text()}
</url>
}
}
</root>

However I get a syntax error message saying that a "{" was encountered when a "," or "}" is expected. I must be missing something obvious. Could someone with more experience or understanding please enlighten me?

Thank you,
--Jim--

Postnext
Minollo I.Subject: Newbie struggling with nested FLWOR expression
Author: Minollo I.
Date: 05 Sep 2007 09:34 PM
Your syntax error can be fixed this way:
<root>
{
let $doc := .
for $ITEM in $doc/ITEMS/ITEM
return (
<catnum>{$ITEM/CATNUM/text()}
</catnum>,
for $IMAGE in $doc/ITEMS/ITEM[CATNUM = $ITEM/CATNUM]/IMAGES/IMAGE
return
<url>
{$IMAGE/URL/text()}
</url>
)
}
</root>

Your nested loop can be written in a simpler way:
<root>
{
let $doc := .
for $ITEM in $doc/ITEMS/ITEM
return (
<catnum>{$ITEM/CATNUM/text()}
</catnum>,
for $IMAGE in $ITEM/IMAGES/IMAGE
return
<url>
{$IMAGE/URL/text()}
</url>
)
}
</root>

Postnext
Jim SalmonsSubject: Newbie struggling with nested FLWOR expression
Author: Jim Salmons
Date: 06 Sep 2007 09:57 AM
Excellent, Minollo! Thank you. So simple yet so elusive to a newbie. The on-line examples tend to be the same ones over and over, with explanations that are rather spartan.

Having spent nearly 25-years as a hardcore Smalltalker, and now with so many years of any-language-that'll-do-the-job, mostly procedural scripting languages, I just need to see examples of what's essential and correct to get the hang of this.

I can see, for example, that the 'best practice' method of Smalltalk object design -- where you write lots of little use case-driven, protocol-oriented methods and don't worry much about when/how they are called, only that they do the right thing with their input and return/perform their specific, expected result -- that this mindset will translate easily to the declarative nature of XQuery 'programming'.

Now if I could just learn to be less anal about result formatting in interactive mode (or if there was a 'pretty priniting' button on the Preview pane, I'd be smokin'! :-)

Your simplified version makes perfect sense and will help me a lot as I move forward.

Thanks,
--Jim--

Posttop
Minollo I.Subject: Newbie struggling with nested FLWOR expression
Author: Minollo I.
Date: 06 Sep 2007 11:37 AM
We understand the pain you are going through, and that's why we have been doing some work recently to put together a list of XQuery tips&tricks from feedback we have received and that we have seen on other discussion lists.

That will soon become public on our http://www.xquery.com website; I'll post a note here when that happens.

 
Go to previous topicPrev TopicGo to next topicNext Topic
Download A Free Trial of Stylus Studio 6 XML Professional Edition Today! Powered by Stylus Studio, the world's leading XML IDE for XML, XSLT, XQuery, XML Schema, DTD, XPath, WSDL, XHTML, SQL/XML, and XML Mapping!  
go

Log In Options

Site Map | Privacy Policy | Terms of Use | Trademarks
Stylus Scoop XML Newsletter:
W3C Member
Stylus Studio® and DataDirect XQuery ™are from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2016 All Rights Reserved.