Here you can find the source of transform(File xslt_source, File xml_source)
Parameter | Description |
---|---|
xslt_source | The XSLT source. |
xml_source | The XML to transform. |
Parameter | Description |
---|---|
TransformerException | an exception |
public static String transform(File xslt_source, File xml_source) throws TransformerException
//package com.java2s; /*/* w ww .j a v a 2s. co m*/ * utils-java8 * Copyright (C) 2014 Raffaele Ragni * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ import java.io.File; import java.io.StringReader; import java.io.StringWriter; import javax.xml.transform.Transformer; import javax.xml.transform.TransformerException; import javax.xml.transform.sax.SAXTransformerFactory; import javax.xml.transform.stream.StreamResult; import javax.xml.transform.stream.StreamSource; public class Main { private static SAXTransformerFactory tf = null; /** * Transforms the XML using an XSLT. * * @param xslt_source The XSLT source. * @param xml_source The XML to transform. * * @return The processed result XML. * * @throws TransformerException */ public static String transform(File xslt_source, File xml_source) throws TransformerException { return transform(new StreamSource(xslt_source), new StreamSource(xml_source)); } /** * Transforms the XML using an XSLT. * * @param xslt_source The XSLT source. * @param xml_source The XML to transform. * * @return The processed result XML. * * @throws TransformerException */ public static String transform(File xslt_source, String xml_source) throws TransformerException { return transform(new StreamSource(xslt_source), new StreamSource(new StringReader(xml_source))); } /** * Transforms the XML using an XSLT. * * @param xslt_source The XSLT source. * @param xml_source The XML to transform. * * @return The processed result XML. * * @throws TransformerException */ public static String transform(String xslt_source, String xml_source) throws TransformerException { return transform(new StreamSource(new StringReader(xslt_source)), new StreamSource(new StringReader(xml_source))); } /** * Transforms the XML using an XSLT. * * @param xslt_source The XSLT source. * @param xml_source The XML to transform. * * @return The processed result XML. * * @throws TransformerException */ public static String transform(StreamSource xslt_source, StreamSource xml_source) throws TransformerException { Transformer t = tf.newTransformer(xslt_source); StringWriter result = new StringWriter(); t.transform(xml_source, new StreamResult(result)); return result.toString(); } }