Created 12-15-2016 05:41 AM
Hi guys,
Is there any process where i can make my XSL File to CSV File?
Thanks.
Created 12-15-2016 06:00 AM
@regie canada you want to convert XSL to CSV? just wanting to confirm you didn't mean XLS.
Created 12-15-2016 05:46 AM
Convert xsl to json using this
https://community.hortonworks.com/articles/29474/nifi-converting-xml-to-json.html
and then convert json to csv using this
Created 12-15-2016 06:00 AM
@regie canada you want to convert XSL to CSV? just wanting to confirm you didn't mean XLS.
Created 12-15-2016 06:11 AM
Hi sir, yes it is XSL. We made a program that will turn our XML to XSL.
This is the current sample output:
1000002746|CRl Campbell|905-899-3495|905-899-3495|lrobert@crlcampbell.com|11675 Burnaby Rd ||Wainfleet|province-ONTA|L0S1V0|Active|HostedIPV_1000003883_SA
We use PIPE for delimiter.
and now I need to make it csv so i can convert it to json.
Thank.
Created 12-15-2016 06:16 AM
i guess based on your comment, use replacetext processor to replace all occurrence of | with ,.
Created 12-15-2016 06:36 AM
you may need header information to convert this to json, technically even the xsl output you have is CSV, just delimited with pipe. I think you can directly use the executescript processor, to call a python script, and go from xsl to json..
getfile (read the file with xsl data ) -> splittext (split the data into lines )-->execute script (with script below to convert to json) --> merge content (merge contents based on fragment.identifier attribute of split text) --> put file (gives you json files )
--- example scrip for converting to json..
import json import java.io from org.apache.commons.io import IOUtils from java.nio.charset import StandardCharsets from org.apache.nifi.processor.io import StreamCallback class PyStreamCallback(StreamCallback): def __init__(self): pass def process(self, inputStream, outputStream): header=["column1","column2","column3"...] # the header for the xsl, this will become the name for json nodes text = IOUtils.toString(inputStream, StandardCharsets.UTF_8) output={} for column in text.split("|"): index=0 # counter to keep track of column, so we can assing a name to the value. output[header(index)]=column outputStream.write(bytearray(json.dumps(output, indent=4).encode('utf-8'))) flowFile = session.get() if (flowFile != None): flowFile = session.write(flowFile,PyStreamCallback()) flowFile = session.putAttribute(flowFile, "filename", flowFile.getAttribute('filename').split('.')[0]+'_translated.json') session.transfer(flowFile, REL_SUCCESS)
Created 12-15-2016 06:56 AM
Thank you so much for answering.
Do I need to install anything to run a python script?
Created 12-15-2016 03:42 PM
@regie canada no you dont have to, it should work out of the box.
Created 02-23-2019 10:58 AM
You can also try this NIFI groovy processor that converts XML to CSV