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
lafosse alexandreSubject: problem with xquery
Author: lafosse alexandre
Date: 07 Dec 2004 04:44 AM
Hi,
I have a mistake with xquery. I have executed this query
with stylus studio. In result, I should have like result, for
each users the number of bids whereas i have only two users.
Do you know what is the mistake?

*********************************************************
<result>
{
for $uid in (doc("bids.xml")//userid),
$u in doc("users.xml")//user_tuple[userid = $uid]
let $b := doc("bids.xml")//bid_tuple[userid = $uid]
order by $u/userid
return
<bidder>
{ $u/userid }
{ $u/name }
<bidcount>{ count($b) }</bidcount>
<avgbid>{ avg($b/bid) }</avgbid>

</bidder>
}
*************************************************************
with this xml documents :

*************************************************************
users.xml
*************************************************************
<users>
<user_tuple>
<userid>U01</userid>
<name>Tom Jones</name>
<rating>B</rating>
</user_tuple>
<user_tuple>
<userid>U02</userid>
<name>Mary Doe</name>
<rating>A</rating>
</user_tuple>
<user_tuple>
<userid>U03</userid>
<name>Dee Linquent</name>
<rating>D</rating>
</user_tuple>
<user_tuple>
<userid>U04</userid>
<name>Roger Smith</name>
<rating>C</rating>
</user_tuple>
<user_tuple>
<userid>U05</userid>
<name>Jack Sprat</name>
<rating>B</rating>
</user_tuple>
<user_tuple>
<userid>U06</userid>
<name>Rip Van Winkle</name>
<rating>B</rating>
</user_tuple>
</users>
***********************************************************
bids.xml
***********************************************************
<bids>
<bid_tuple>
<userid>U02</userid>
<itemno>1001</itemno>
<bid>35</bid>
<bid_date>1999-01-07</bid_date>
</bid_tuple>
<bid_tuple>
<userid>U04</userid>
<itemno>1001</itemno>
<bid>40</bid>
<bid_date>1999-01-08</bid_date>
</bid_tuple>
<bid_tuple>
<userid>UO2</userid>
<itemno>1001</itemno>
<bid>45</bid>
<bid_date>1999-01-11</bid_date>
</bid_tuple>
<bid_tuple>
<userid>UO4</userid>
<itemno>1001</itemno>
<bid>50</bid>
<bid_date>1999-01-13</bid_date>
</bid_tuple>
<bid_tuple>
<userid>UO2</userid>
<itemno>1001</itemno>
<bid>55</bid>
<bid_date>1999-01-15</bid_date>
</bid_tuple>
<bid_tuple>
<userid>UO1</userid>
<itemno>1002</itemno>
<bid>400</bid>
<bid_date>1999-02-14</bid_date>
</bid_tuple>
<bid_tuple>
<userid>UO2</userid>
<itemno>1002</itemno>
<bid>600</bid>
<bid_date>1999-02-16</bid_date>
</bid_tuple>
<bid_tuple>
<userid>UO3</userid>
<itemno>1002</itemno>
<bid>800</bid>
<bid_date>1999-02-17</bid_date>
</bid_tuple>
<bid_tuple>
<userid>UO4</userid>
<itemno>1002</itemno>
<bid>1000</bid>
<bid_date>1999-02-25</bid_date>
</bid_tuple>
<bid_tuple>
<userid>UO2</userid>
<itemno>1002</itemno>
<bid>1200</bid>
<bid_date>1999-03-02</bid_date>
</bid_tuple>
<bid_tuple>
<userid>UO4</userid>
<itemno>1003</itemno>
<bid>15</bid>
<bid_date>1999-01-22</bid_date>
</bid_tuple>
<bid_tuple>
<userid>UO5</userid>
<itemno>1003</itemno>
<bid>20</bid>
<bid_date>1999-02-03</bid_date>
</bid_tuple>
<bid_tuple>
<userid>UO1</userid>
<itemno>1004</itemno>
<bid>40</bid>
<bid_date>1999-03-05</bid_date>
</bid_tuple>
<bid_tuple>
<userid>UO3</userid>
<itemno>1007</itemno>
<bid>175</bid>
<bid_date>1999-01-25</bid_date>
</bid_tuple>
<bid_tuple>
<userid>UO5</userid>
<itemno>1007</itemno>
<bid>200</bid>
<bid_date>1999-02-08</bid_date>
</bid_tuple>
<bid_tuple>
<userid>UO4</userid>
<itemno>1007</itemno>
<bid>225</bid>
<bid_date>1999-02-12</bid_date>
</bid_tuple>
</bids>
**************************************************************

Postnext
Alberto MassariSubject: problem with xquery
Author: Alberto Massari
Date: 07 Dec 2004 05:16 AM
Hi Alexandre,
to get the expected results you need to change the first "for"
statement with this line

for $uid in distinct-values(doc("bids.xml")//userid),

Otherwise you will generate one <bidder> node for each bid that has
been placed, instead of for each user that has placed at least one bid.

Hope this helps,
Alberto

P.S. the query you pasted in the message was missing the closing </result>
tag.

Postnext
lafosse alexandreSubject: problem with xquery
Author: lafosse alexandre
Date: 07 Dec 2004 05:21 AM
Hi, thank you for your answer but I have tested the new query and
I have the same result (only 2 bidder...).

<result>
{
for $uid in distinct-values(doc("bids.xml")//userid),
$u in doc("users.xml")//user_tuple[userid = $uid]
let $b := doc("bids.xml")//bid_tuple[userid = $uid]
order by $u/userid
return
<bidder>
{ $u/userid }
{ $u/name }
<bidcount>{ count($b) }</bidcount>
<avgbid>{ avg($b/bid) }</avgbid>

</bidder>
}
</result>

Posttop
Alberto MassariSubject: problem with xquery
Author: Alberto Massari
Date: 07 Dec 2004 05:49 AM
Hi Alexandre,
check your bids.xml file; it looks like the official bids.xml from the
use cases, but, starting from the third "bid_tuple", it uses a capital "o"
instead of a zero in the user id.

Alberto

 
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.