Java XML Document Transform transformDocument(Document doc, String xsl, String targetFile)

Here you can find the source of transformDocument(Document doc, String xsl, String targetFile)

Description

transform Document

License

Open Source License

Declaration

public static void transformDocument(Document doc, String xsl, String targetFile) 

Method Source Code

//package com.java2s;
/*********************************************************************************************
 * /*  www  .  j  a v  a  2 s.  c  o  m*/
 *
 * 'XMLUtils.java', in plugin 'msi.gama.documentation', is part of the source code of the 
 * GAMA modeling and simulation platform.
 * (c) 2007-2014 UMI 209 UMMISCO IRD/UPMC & Partners
 * 
 * Visit https://code.google.com/p/gama-platform/ for license information and developers contact.
 * 
 * 
 **********************************************************************************************/

import java.io.File;

import javax.xml.transform.OutputKeys;
import javax.xml.transform.Result;
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.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;
import org.w3c.dom.Document;

public class Main {
    public static void transformDocument(Document doc, String xsl, String targetFile) {
        try {
            Source source = new DOMSource(doc);

            // Creation of the output file
            File file = new File(targetFile);
            Result result = new StreamResult(file);

            // configuration of the transformer
            TransformerFactory factoryT = TransformerFactory.newInstance();
            StreamSource stylesource = new StreamSource(xsl);
            Transformer transformer;

            transformer = factoryT.newTransformer(stylesource);
            transformer.setOutputProperty(OutputKeys.METHOD, "text");

            // Transformation
            transformer.transform(source, result);
        } catch (TransformerConfigurationException e) {
            e.printStackTrace();
        } catch (TransformerException e) {
            e.printStackTrace();
        }

    }
}

Related

  1. transform(Document dom, Document xslt)
  2. transform(final Document document, final StreamResult streamResult, final boolean xmlDeclaration)
  3. transform(Source xsl, Document doc)
  4. transformDoc(Document doc)
  5. transformDocToFile(Document doc, File file)
  6. transformDocument(Document xmlDocument, String xsltFilename)
  7. transformDocumentAsString(Document xmlDocument, Map parameters, String xsltFilename)
  8. transformDomDocument(Transformer transformer, Node node, OutputStream os)
  9. transformXmlToString(Document importPackageDocument)