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)
- Stylus Studio FAQs (159)
-> - XML Publisher painting problem... (1)
-> + Windows Installer (Not Respond... (2)
-> - system property org.xml.sax.dr... (1)
-> - Demonstration of CSV to Fixed-... (1)
-> - The Java Virtual Machine is re... (1)
-> - JDBC Users Guide (1)
-> - Connect for SQL/XML Questions (1)
-> - struzzo.exe has 10-25% cpu usa... (1)
-> - 'crossgrade' with SSL? (1)
-> + what happens with xmlspy licen... (3)
-> + crossgrade cheaper then update... (2)
-> + New to XML (2)
-> - Version 6 - price increase (1)
-> + XSD documentation (2)
-> + New Tutorial: How to Configure... (2)
-> + In dtd, Group comes first (2)
-> + converting DTD to Schema (3)
-> - New FAQ for Stylus Studio Home... (1)
-> + Project - Add New Document - a... (6)
-> + XSLT - Mapper view - And Or (2)
-- [1-20] [21-40] [41-60] Next
+ Stylus Studio Code Samples & Utilities (364)
+ Stylus Studio Announcements (113)
Topic  
Posttop
Tony LavinioSubject: Demonstration of CSV to Fixed-Width transform
Author: Tony Lavinio
Date: 14 Jan 2005 03:43 PM
Stylus Studio can be used to do two-step transformations easily.

For example, suppose the input format is a CSV file, but you need a
fixed-width file as output.

The first step would be to get the input file into XML, so that we can
work with it. Using the adapters supplied with Stylus Studio, this is
done very simply.

We are going to use the following input file called bikes.csv:

--------------------------------------------------
brand,year,mileage
bmw,2004,14274
kawasaki,1996,60234
ducati,1997,24000
--------------------------------------------------

The output will be fixed-width, where the "brand" column is 12 bytes
wide and left-justified, the "year" column is 4 bytes wide and
left-justified, and the "mileage" column is 8 bytes wide and
right-justified. Our output file won't have any separators between the
24-byte records this will yield, so the output file will look like this:

--------------------------------------------------
bmw 2004 14274kawasaki 1996 60234ducati 1997 24000
--------------------------------------------------

To just see the CSV file in the editor converted to XML, do the
following:

1. File > Open and choose the .csv file, and put a check in the
"Convert to XML using adapter" box.

2. When the next screen comes up, choose the Comma-Separated Values
option and press OK.

To actually do the conversion, use the attached stylesheet. The hardest
part of this whole operation is doing the left- and right-padding of
values.


Documentcsv-to-fixed.xsl
CSV to Fixed-Width stylesheet

Documentbikes.csv
Sample CSV input file

   
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.