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
Neal  WaltersSubject: Xquery to find sample data file for testing
Author: Neal Walters
Date: 28 Jun 2005 09:30 AM
In a previous post entitled "XQuery on all XML Files in a Directory?",
Ivan helped me use Xquery to read all files in a directory.

Today, I'm tring to find a sample Amazon order that has more one line line item. The following code works, but I have to questions:

declare namespace ext = "FileUtils";
declare function ext:listFiles($path as xs:string) as xs:string* external;
declare variable $dirname as xs:string := "file:///c:/Odimo/Amazon/FileDrop/WorldOfWatches/Order__89/Doc_Original_Backup/";
<OrderReport>
{
for $filename in fn:tokenize(ext:listFiles($dirname), ",")
[fn:matches(., ".xml")]
, $rootel in doc(fn:concat($dirname, "/", $filename))
return
<filename name='{$filename}'>
<OrderID>{$rootel//Message/OrderReport/AmazonOrderID}</OrderID>
<ItemCount>{count($rootel//Message/OrderReport/Item)}</ItemCount>
</filename>
}
</OrderReport>

Question 1:
Is there a way to limit the output to only those files (orders) that have a count >= 2 {count($rootel//Message/OrderReport/Item)?

Question 2:
if I don't put two slashes here:
<OrderID>{$rootel//Message/OrderReport/AmazonOrderID}</OrderID>
I don't get anything. Why doesn't one slash work between $rootel and Message? From Stylus Studio, I can open a source doc, go to tree view,
and generate the following xpath:
/AmazonEnvelope/Message[1]/OrderReport[1]/AmazonOrderID[1]

Thanks!
Neal Walters
http://Biztalk-Training.com




Postnext
(Deleted User) Subject: Xquery to find sample data file for testing
Author: (Deleted User)
Date: 28 Jun 2005 09:47 AM
Hi Neil,

1) to limit the output of a FLWOR block you use the "where" statement, e.g.

for $filename in fn:tokenize(ext:listFiles($dirname), ",")[fn:matches(., ".xml")]
, $rootel in doc(fn:concat($dirname, "/", $filename))
where count($rootel//Message/OrderReport/Item) >=2
return
...

2) $rootel is bound to the return value of fn:doc, that is a document node, so the correct path is $rootel/AmazonEnvelope/Message/...

Hope this helps,
Alberto

Postnext
Neal  WaltersSubject: Xquery to find sample data file for testing
Author: Neal Walters
Date: 29 Jun 2005 11:56 AM
Thanks - the where/count worked great, but...

2) $rootel is bound to the return value of fn:doc, that is a document node, so the correct path is $rootel/AmazonEnvelope/Message/...

I agree what the correct path should be, but it's not working.

return
<filename name='{$filename}'>
<OrderID>{$rootel/Message/OrderReport/AmazonOrderID}</OrderID>
<ItemCount>{count($rootel//Message/OrderReport/Item)}</ItemCount>
</filename>

results in this:

<OrderReport>
<filename name="70435463-83b3b70-83a3ae8-83f7970-86102f8-8608610.xml">
<OrderID/>
<ItemCount>2</ItemCount>
</filename>

same thing with two slashes instead of one on the OrderID:

return
<filename name='{$filename}'>
<OrderID>{$rootel//Message/OrderReport/AmazonOrderID}</OrderID>
<ItemCount>{count($rootel//Message/OrderReport/Item)}</ItemCount>
</filename>

results in this:

<OrderReport>
<filename name="70435463-83b3b70-83a3ae8-83f7970-86102f8-8608610.xml">
<OrderID>
<AmazonOrderID>058-3261266-8080327</AmazonOrderID>
<AmazonOrderID>058-3612269-1080319</AmazonOrderID>
</OrderID>
<ItemCount>2</ItemCount>
</filename>

Input file begins like this:

<?xml version="1.0" encoding="UTF-8"?>
<AmazonEnvelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="amzn-envelope.xsd">
<MessageType>OrderReport</MessageType>
<Message>
<MessageID>1</MessageID>
<OrderReport>
<AmazonOrderID>058-2840493-5587508</AmazonOrderID>
<AmazonSessionID>104-4155613-9935151</AmazonSessionID>

Any ideas?
Thanks,
Neal


Posttop
(Deleted User) Subject: Xquery to find sample data file for testing
Author: (Deleted User)
Date: 01 Jul 2005 04:33 AM
Hi Neal,
>Thanks - the where/count worked great, but...
>
>2) $rootel is bound to the return value of fn:doc, that
>is a document node, so the correct path is
>$rootel/AmazonEnvelope/Message/...
>
>I agree what the correct path should be, but it's not
>working.
>
>return
><filename name='{$filename}'>
><OrderID>{$rootel/Message/OrderReport/AmazonOrderID}</OrderID>
><ItemCount>{count($rootel//Message/OrderReport/Item)}</ItemCount>
></filename>

In my message I suggested you to try this code:

return
<filename name='{$filename}'>
<OrderID>{$rootel/AmazonEnvelope/Message/OrderReport/AmazonOrderID}</OrderID>
<ItemCount>{count($rootel/AmazonEnvelope/Message/OrderReport/Item)}</ItemCount>
</filename>

Can you try it?

Alberto

   
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.