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
Conferences Close Tree View
+ Stylus Studio Feature Requests (1192)
+ Stylus Studio Technical Forum (14621)
+ Website Feedback (249)
+ XSLT Help and Discussion (7625)
- XQuery Help and Discussion (2017)
-> + Issue with Processing Instruct... (2)
-> + problem converting json to XML... (2)
-> + Problem base64 decoding string... (3)
-> + Problems posting multipart for... (5)
-> + trouble with download of price... (2)
-> + Problem with http-post not bei... (3)
-> + path problem, xps_file:writeAl... (9)
-> + Xquery update support? (2)
-> + problem with Stylus studio try... (5)
-> + adding dtd reference to xml ou... (4)
-> + xquery escaping ambarsand when... (3)
-> + Whitespace problem when return... (5)
-> + Problem with namespace prefix ... (5)
-> - Sending via SFTP returns unexp... (1)
-> + Query and Sftp clent (4)
-> + xquery and try - catch (3)
-> + Query + ddtek:http-post optio... (5)
-> + Example files referenced in do... (3)
-> + Automatic Error Detection and ... (3)
-> + Working with result of ddtek:h... (2)
-- [1-20] [21-40] [41-60] Next
+ Stylus Studio FAQs (159)
+ Stylus Studio Code Samples & Utilities (364)
+ Stylus Studio Announcements (113)
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.

   
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.