Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import java.io.File;

import java.io.StringWriter;

import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;

public class Main {
    public static String transform(String xmlFilePath, String xsltFilePath) throws Exception {
        StreamResult result = new StreamResult(new StringWriter());
        StreamSource s = new StreamSource(new File(xsltFilePath));
        StreamSource xml = new StreamSource(new File(xmlFilePath));

        Transformer transformer = TransformerFactory.newInstance().newTransformer(s);
        transformer.transform(xml, result);

        String response = result.getWriter().toString();

        return response;
    }
}