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)
-> - Proposal to Add Git Support to... (1)
-> + XML formatter option request (3)
-> - Could Pipeline input scenario ... (1)
-> + XML Traversal in XSLT Mapper (2)
-> + Email not in HTML as expected (3)
-> + My SS Open [tools]==>.[option... (3)
-> + Fonts in Stylus Studio (2)
-> - Fix the check for concurrent s... (1)
-> + Stylus is showing the error fo... (2)
-> - XML editor (1)
-> + Unable to see filename in sche... (2)
-> + Unable to connect to JVM (2)
-> - Stylus Studio forum questions (1)
-> + User Interface - X16 Enterpris... (2)
-> + Stylus Studio High DPI support (2)
-> + target xsd includes and import... (2)
-> + XML/EDIFACT Schema (3)
-> + Options to control whether BOM... (2)
-> + Snippets and/or Emmet integrat... (2)
-> + internal error accessing metho... (2)
-- [1-20] [21-40] [41-60] Next
+ Stylus Studio Technical Forum (14621)
+ Website Feedback (249)
+ XSLT Help and Discussion (7625)
+ XQuery Help and Discussion (2016)
+ Stylus Studio FAQs (159)
+ Stylus Studio Code Samples & Utilities (364)
+ Stylus Studio Announcements (113)
Topic  
Postnext
Martin BörlinSubject: Dynamic CSV to XML
Author: Martin Börlin
Date: 03 Oct 2006 10:42 AM
Hi!

I work in a project where we need to convert CSV files (no format defined yet) to a given XML format.
The CSV will have to be dynamic (yes, I know: why don't you use XML, this is like inventing another XML clone...) and an idea to make them dynamic is to prefix each line and then use a "proper" line-oriented comma separated values for each line, based on the prefix. I.e. in my example below the line starting with "order" must have no other fields on that line, the line starting with "customer" must have 8 fields where field number 2 is a first name, field 3 is a last name etc. The "order" ends when a new "order" line is found.

Is it possible to define this using Stylus Studio, and if so; how? Any comments/suggestions about my 30-seconds-dynamic-CSV-fomat is appreciated!

regards
-Martin Börlin


CSV:

order
customer, Martin, Börlin, Tranebergsvägen 52, , Bromma,,
productADSL,1024, , 4620903
productMobile, 0703992050, work, secret, VoiceMail
productVoIp, 4620903
productMobile, 0703110017, home, ,
order
customer, Pia, Börlin, Tranebergsvägen 52, , Bromma,,
productADSL, 1024, , 4620903
productMobile, 0703992050, work, secret, VoiceMail
order
customer, Selma, Börlin, Tranebergsvägen 52, , Bromma,,
productVoIp, 4620903

corresponding XML:

<order>
<customer>
<firstName>Martin</firstName>
<lastName>Börlin</lastName>
<street>Tranebergsvägen 52</street>
<postalCode></postalCode>
<city>Bromma</city>
<region></region>
<country></country>
</customer>
<products>
<product>
<adsl>
<size>1024</size>
<someValue></someValue>
<number></number>
</adsl>
</product>
<product>
<mobile>
<msisdn>0703992050</msisdn>
<type>work</type>
<visability>secret</visability>
<extras>Voicemail</extras>
</mobile>
</product>
<product>
<voip>
<number>4620903</number>
</voip>
</product>
<product>
<mobile>
<msisdn>0703110017</msisdn>
<type>home</type>
<visability></visability>
<extras></extras>
</mobile>
</product>
</products>
</order>
<order>
<customer>
<firstName>Pia</firstName>
<lastName>Börlin</lastName>
<street>Tranebergsvägen 52</street>
<postalCode></postalCode>
<city>Bromma</city>
<region></region>
<country></country>
</customer>
<products>
<product>
<adsl>
<size>1024</size>
<someValue></someValue>
<number></number>
</adsl>
</product>
<product>
<mobile>
<msisdn>0703992050</msisdn>
<type>work</type>
<visability>secret</visability>
<extras>Voicemail</extras>
</mobile>
</product>
</products>
</order>
<order>
[etc...]
</order>

Postnext
Tony LavinioSubject: Dynamic CSV to XML
Author: Tony Lavinio
Date: 03 Oct 2006 11:10 AM
It can be done without much difficulty.

I'd use the CSV adapter to read in the data, and a piece of
XSLT using grouping to sort it out.

Postnext
Martin BörlinSubject: Dynamic CSV to XML
Author: Martin Börlin
Date: 04 Oct 2006 02:07 AM
Hi Tony, and thanks for your reply!

I'm new to Stylus Studio so could you please expand your ideas of how to solve my problem? Can I generate Java code so I can use it on the fly from a web app?

Thanks
-Martin

>It can be done without much
>difficulty.
>
>I'd use the CSV adapter to
>read in the data, and a piece
>of
>XSLT using grouping to sort it
>out.

Postnext
Tony LavinioSubject: Dynamic CSV to XML
Author: Tony Lavinio
Date: 09 Oct 2006 09:30 AM
Okay, here it is.

We use Convert-to-XML to read in the original file and convert it
into a 'flat' XML file.

Then we use XSLT to group the customer and various product records
under each order.

To run this, just open the .conv file in Stylus Studio and press the
green triangle. The input is already set to come through the Convert
to XML module (which you can see in the scenario editor).


Unknownmartin.csv
The comma-separated-value raw input file

Unknownmartin.conv
The Convert-to-XML map

Unknownmartin.xsl
The XSLT to group order parts together

Posttop
Martin BörlinSubject: Dynamic CSV to XML
Author: Martin Börlin
Date: 10 Oct 2006 03:55 AM
Excellent!
Thank you so much, Tony!

And the generated Java code works fine too.

Kind regards
-Martin

   
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.