Support Questions

Find answers, ask questions, and share your expertise

XSL to CSV using NiFi

Hi guys,

Is there any process where i can make my XSL File to CSV File?



Expert Contributor

@regie canada you want to convert XSL to CSV? just wanting to confirm you didn't mean XLS.

View solution in original post


Super Guru

Expert Contributor

@regie canada you want to convert XSL to CSV? just wanting to confirm you didn't mean XLS.

@Karthik Narayanan

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


Expert Contributor

i guess based on your comment, use replacetext processor to replace all occurrence of | with ,.

Expert Contributor

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
from import IOUtils
from java.nio.charset import StandardCharsets
from import StreamCallback

class PyStreamCallback(StreamCallback):
  def __init__(self):
  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)
    for column in text.split("|"):
	index=0 # counter to keep track of column, so we can assing a name to the value.
	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)

@Karthik Narayanan

Thank you so much for answering.

Do I need to install anything to run a python script?

Expert Contributor

@regie canada no you dont have to, it should work out of the box.

You can also try this NIFI groovy processor that converts XML to CSV