Skip to content
Ceri Binding edited this page Oct 28, 2016 · 44 revisions

STELETO wiki

STELETO is a simple 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/. STELATO 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)

Example usage

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  

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  

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>  

Usage

Clone this wiki locally