Here you can find the source of transformLogViaXSLT(String logFilePath, String xslFilePath)
public static String transformLogViaXSLT(String logFilePath, String xslFilePath) throws TransformerConfigurationException, TransformerException, IOException
//package com.java2s; /******************************************************************************* * Copyright 2013 Khepry Software/* ww w . j a v a2s .c o m*/ * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. ******************************************************************************/ import java.io.ByteArrayOutputStream; import java.io.File; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Paths; import javax.xml.transform.Source; import javax.xml.transform.Transformer; import javax.xml.transform.TransformerConfigurationException; import javax.xml.transform.TransformerException; import javax.xml.transform.TransformerFactory; import javax.xml.transform.stream.StreamResult; import javax.xml.transform.stream.StreamSource; public class Main { public static String transformLogViaXSLT(String logFilePath, String xslFilePath) throws TransformerConfigurationException, TransformerException, IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); File logFile = new File(logFilePath); if (logFile.exists()) { File xslFile = new File(xslFilePath); if (xslFile.exists()) { TransformerFactory factory = TransformerFactory.newInstance(); Source xslt = new StreamSource(new File(xslFilePath)); Transformer transformer = factory.newTransformer(xslt); Source logXmlText = new StreamSource(new File(logFilePath)); transformer.transform(logXmlText, new StreamResult(baos)); return baos.toString(); } else { return new String(Files.readAllBytes(Paths.get(logFilePath))); } } else { return baos.toString(); } } }