Java XML Document Transform xslt(InputStream stylesheet, Document input)

Here you can find the source of xslt(InputStream stylesheet, Document input)

Description

xslt

License

Open Source License

Declaration

public static Document xslt(InputStream stylesheet, Document input)
            throws FileNotFoundException, TransformerException, ParserConfigurationException 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.io.FileNotFoundException;

import java.io.InputStream;

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

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

import javax.xml.transform.stream.StreamSource;

import org.w3c.dom.Document;

public class Main {
    public static Document xslt(InputStream stylesheet, Document input)
            throws FileNotFoundException, TransformerException, ParserConfigurationException {
        TransformerFactory tFactory = TransformerFactory.newInstance();
        Transformer transformer = tFactory.newTransformer(new StreamSource(stylesheet));
        Document result = newDocument();
        DOMResult domResult = new DOMResult(result);
        transformer.transform(new DOMSource(input), domResult);
        return result;
    }/*from ww  w  .  j a va2s  .c  om*/

    public static Document newDocument() throws ParserConfigurationException {
        return getDocumentBuilder().newDocument();
    }

    public static DocumentBuilder getDocumentBuilder() throws ParserConfigurationException {
        DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
        dbFactory.setNamespaceAware(true);
        return dbFactory.newDocumentBuilder();
    }
}

Related

  1. transformDocumentAsString(Document xmlDocument, Map parameters, String xsltFilename)
  2. transformDomDocument(Transformer transformer, Node node, OutputStream os)
  3. transformXmlToString(Document importPackageDocument)
  4. transformXmlToString(Document payload)
  5. transformXMLtoString(Document xmldoc)
  6. xslTransform(Document xmlDoc, Document xslDoc)