|
next
|
 Subject: 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
|
next
|
 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
|
|
|
|