Here you can find the source of transformXmlByXslt(StreamSource source, URI xslFile)
Parameter | Description |
---|---|
source | The xml file to transform. |
xslFile | The xsl file. |
static ByteArrayOutputStream transformXmlByXslt(StreamSource source, URI xslFile) throws TransformerException, IOException
//package com.java2s; /*/*from w w w . ja v a 2 s . c o m*/ * (c) Kitodo. Key to digital objects e. V. <contact@kitodo.org> * * This file is part of the Kitodo project. * * It is licensed under GNU General Public License version 3 or later. * * For the full copyright and license information, please read the * GPL3-License.txt file that was distributed with this source code. */ import java.io.ByteArrayOutputStream; import java.io.IOException; import java.net.URI; import javax.xml.transform.Transformer; 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 { /** * Transforms a xml file by xslt and returns the result as string. * * @param source The xml file to transform. * @param xslFile The xsl file. * @return The Result of the transformation as String object. */ static ByteArrayOutputStream transformXmlByXslt(StreamSource source, URI xslFile) throws TransformerException, IOException { StreamSource xsltSource = new StreamSource(xslFile.getPath()); TransformerFactory factory = TransformerFactory.newInstance(); Transformer transformer = factory.newTransformer(xsltSource); try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) { StreamResult result = new StreamResult(outputStream); transformer.transform(source, result); return outputStream; } } }