-
Notifications
You must be signed in to change notification settings - Fork 0
Home
STELETO is a simple cross-platform command line application to convert tabular data into other textual formats, via a custom template. It takes a delimited text data file as input, applies the specified template and creates a text file as output. STELETO uses the StringTemplate templating engine "String Template Group" file format, so for further details of the template syntax to use refer to http://www.stringtemplate.org/. STELETO looks for the following named templates and uses them if they are present:
* HEADER(options) ::= "" // called once at the start of processing
* RECORD(data, options) ::= "" // called once per record of the input file
* FOOTER(options) :: = "" // called once at the end of processing
'data' contains the named fields from the current row of the input data
'options' contains any additional data items passed in via the -p parameter (see below)
Some example comma-delimited text input (save as 'c:\tmp\mydata.csv'):
ref,name,qty
A1234,apples,5127
A2345,bananas,235
A3456,pears,8756
An example template to be applied to each record in the input data (save as 'c:\tmp\data2text.stg', ensuring your template finishes with a blank line):
// start of the template
delimiters "{", "}"
RECORD(data, options) ::= <<
Reference : {data.ref}
Description : {data.name} [{data.qty}]
>>
// end of the template
Windows command to perform the conversion:
cd \path\to\steleto
STELETO -i:"c:\tmp\mydata.csv" -o:"c:\tmp\output.txt" -t:"c:\tmp\data2text.stg" -f -d:","
Contents of the resultant output file (c:\tmp\output.txt):
Reference : A1234
Description : apples [5127]
Reference : A2345
Description : bananas [235]
Reference : A3456
Description : pears [8756]
###Parameters The STELETO parameters may be present in any order (STELETO -h for help):
-i [required] - the name of the input data file (including path)
-o [required] - the name of the output data file (including path)
-t [required] - the name of the template file (including path)
-f [optional] - indicates the first line of the input data contains field names
-d [optional] - indicates the delimiter used in the input data (default is tab delimited)
-p [optional] - any additional named parameter options passed to the template (-p:name:value)
Now an alternative template, to create XML from the same input data (save as 'c:\tmp\data2xml.stg'):
// start of the template
delimiters "{", "}"
HEADER(options) ::= <<
<?xml version="1.0" encoding="UTF-8"?>
<items>
>>
RECORD(data, options) ::= <<
<item rdf:about="{options.uri}{data.ref}">
<description>{data.name}</description>
<quantity>{data.qty}</quantity>
</item>
>>
FOOTER(options) ::= "</items>"
// end of the template
Windows command to perform the conversion:
STELETO -i:"c:\tmp\mydata.csv" -o:"c:\tmp\output.xml" -t:"c:\tmp\data2xml.stg" -f -d:"," -p:uri:"http://temp1/"
Contents of the resultant output file (c:\tmp\output.xml):
<?xml version="1.0" encoding="UTF-8"?>
<items>
<item rdf:about="http://temp1/A1234">
<description>apples</description>
<quantity>5127</quantity>
</item>
<item rdf:about="http://temp1/A2345">
<description>bananas</description>
<quantity>235</quantity>
</item>
<item rdf:about="http://temp1/A3456">
<description>pears</description>
<quantity>8756</quantity>
</item>
</items>
###STELETO also works on Linux! Not extensively tested, but the existing compiled application will also run on LINUX (using the mono platform). To test this we created a UBUNTU blank workspace on Cloud9 (see http://c9.io/). We installed the mono platform using the following commands:
sudo apt-get update
sudo apt-get install mono-complete
We then uploaded the STELETO /bin/Release directory and the data file and the two .stg templates from the earlier examples, navigated to the directory containing the data file and templates, and typed the following commands:
$ mono ./bin/Release/STELETO.exe -i:"mydata.csv" -o:"output.txt" -t:"data2text.stg" -f -d:","
STELETO v1.0
Convert 'mydata.csv' with template 'data2text.stg'
3 rows converted [time taken: 00:00:00.178]
$ mono ./bin/Release/STELETO.exe -i:"mydata.csv" -o:"output.xml" -t:"data2xml.stg" -f -d:","
STELETO v1.0
Convert 'mydata.csv' with template 'data2xml.stg'
3 rows converted [time taken: 00:00:00.311]
The two output files were created successfully as documented in the earlier examples