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
Doug LundinSubject: Save results of XQuery as CSV?
Author: Doug Lundin
Date: 27 Sep 2006 03:19 PM
All,

I have created a XQuery that successfully maps to an XML file but am trying to get the mapping to a simple CSV or even space-delimited output file.

How can this be done?

Thanks

declare namespace a = "http://www.w3.org/1999/xhtml";
<CompanyMetadata>
<AvgVol>
{/a:html/a:body[1]/a:div[1]/a:div[3]/a:table[2]/a:tr[1]/a:td[1]/a:table[3]/a:tr[1]/a:td[3]/a:table[1]/a:tr[1]/a:td[1]/a:table[1]/a:tr[4]/a:td[2]/text()}
</AvgVol>
(... more junk cut out here)
</CompanyMetadata>

Postnext
Tony LavinioSubject: Save results of XQuery as CSV?
Author: Tony Lavinio
Date: 28 Sep 2006 01:49 AM
Instead of sending the output to a file with a name like this:
file:///c:/myfile.txt

try something like this:
adapter:CSV?file:///c:/myfile.txt

That will pipe the output through the CSV adapter, turning the first
level of elements under the root into lines, and the second level of
elements under the root into comma-separated fields of data.

Postnext
Doug LundinSubject: Save results of XQuery as CSV?
Author: Doug Lundin
Date: 28 Sep 2006 10:52 AM
I've been tinkering with this and can't seem to get it to work. Perhaps I'm making this change in the wrong place. I've got Stylus Enterprise opened with my xquery loaded. I open my scenario and when the Output URL is set to file:///c:/myfile.txt I get the expected output. When I change it to adapter:CSV?file:///c:/myfile.txt I get an empty file.

What am I doing wrong?

Thanks

Postnext
Tony LavinioSubject: Save results of XQuery as CSV?
Author: Tony Lavinio
Date: 29 Sep 2006 12:23 AM
Can you attach a sample of the XML you get after transforming
when you aren't using the adapter? You can email it to
stylus-field-report (at) progress.com, or attach it here, and
we'll take a look.

Postnext
Doug LundinSubject: Save results of XQuery as CSV?
Author: Doug Lundin
Date: 02 Oct 2006 10:56 AM
Here is a sample - no adapter being used:
<CompanyMetadata>
<Col1>44,093,500</Col1>
<Col2>11.75</Col2>
</CompanyMetadata>

What I would like to get is
44093500, 11.75

Thanks

Postnext
Doug LundinSubject: Save results of XQuery as CSV?
Author: Doug Lundin
Date: 02 Oct 2006 11:04 AM
It just occured to me that I am trying to place the adapter on the output side of the XQuery - you're not suggesting it go on the input side, are you?

Posttop
Tony LavinioSubject: Save results of XQuery as CSV?
Author: Tony Lavinio
Date: 03 Oct 2006 11:03 AM
I think you need one more level of element in your output.
In order to write through the CSV adapter, you need a root
element, and then a row element, and then column elements.

I tried a simple XQuery program that consisted of just this:
<CompanyMetadata><Col1>44,093,500</Col1><Col2>11.75</Col2></CompanyMetadata>
and I got just a CR/LF in my output file. The reason? No
root element - Stylus Studio just saw CompanyMetadata as the
root, and Col1 and Col2 as row names.

If I change it to
<CompanyMetadata><Row><Col1>44,093,500</Col1><Col2>11.75</Col2></Row></CompanyMetadata>
then I get
"44,093,500",11.75
as my output.

Here is the output URL I used:
adapter:CSV?file:///c:/temp/lundin.txt

Does this help?

 
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.