|
top
|
Subject: 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. csv-to-fixed.xsl CSV to Fixed-Width stylesheet
bikes.csv Sample CSV input file
|
|
|