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
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

 
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.