Java XML Document Transform transform(Document dom, Document xslt)

Here you can find the source of transform(Document dom, Document xslt)

Description

transform

License

Apache License

Declaration

public static Document transform(Document dom, Document xslt) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;

import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMResult;
import javax.xml.transform.dom.DOMSource;

import org.w3c.dom.Document;

public class Main {
    /**/*from   www. j a  va 2 s  .  c  o  m*/
     * Document builder factory
     */
    private static DocumentBuilderFactory factory = null;
    private static TransformerFactory transFactory = null;

    public static Document transform(Document dom, Document xslt) {
        try {
            DOMSource xsltSource = new DOMSource(xslt);
            Transformer transformer = transFactory.newTransformer(xsltSource);
            DOMSource source = new DOMSource(dom);
            Document out = newDocument();
            DOMResult result = new DOMResult(out);
            transformer.transform(source, result);
            return out;
        } catch (Exception e) {
            throw new RuntimeException("Could not write dom tree '" + dom.getBaseURI() + "'!", e);
        }
    }

    /**
     * Creates a new Document using the default XML implementation
     * 
     * @return DOM
     */
    public static Document newDocument() {
        try {
            return factory.newDocumentBuilder().newDocument();
        } catch (ParserConfigurationException e) {
            throw new RuntimeException(e.getMessage(), e);
        }
    }
}

Related

  1. transfer(Document doc, String filepath)
  2. transform(Document doc, Result result)
  3. transform(Document doc, Result result)
  4. transform(Document doc, StreamSource xslInput, String systemid)
  5. transform(Document document, Properties outputProperties, StreamResult streamResult)
  6. transform(final Document document, final StreamResult streamResult, final boolean xmlDeclaration)
  7. transform(Source xsl, Document doc)
  8. transformDoc(Document doc)
  9. transformDocToFile(Document doc, File file)