Java XML Document Transform xslTransform(Document xmlDoc, Document xslDoc)

Here you can find the source of xslTransform(Document xmlDoc, Document xslDoc)

Description

Performs XSL transformation.

License

CDDL license

Parameter

Parameter Description
xmlDoc Document
xslDoc Document

Exception

Parameter Description
TransformerConfigurationException an exception
TransformerException an exception

Return

String The output text.

Declaration

public static String xslTransform(Document xmlDoc, Document xslDoc)
        throws TransformerConfigurationException, TransformerException 

Method Source Code

//package com.java2s;
/*//from   ww w.  j  a  va 2s .  co m
Copyright (c) 2013 eBay, Inc.
This program is licensed under the terms of the eBay Common Development and
Distribution License (CDDL) Version 1.0 (the "License") and any subsequent  version 
thereof released by eBay.  The then-current version of the License can be found 
at http://www.opensource.org/licenses/cddl1.php and in the eBaySDKLicense file that 
is under the eBay SDK ../docs directory.
*/

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 org.w3c.dom.Document;

public class Main {
    /**
     * Performs XSL transformation.
     * @param xmlDoc Document
     * @param xslDoc Document
     * @throws TransformerConfigurationException
     * @throws TransformerException
     * @return String The output text.
     */
    public static String xslTransform(Document xmlDoc, Document xslDoc)
            throws TransformerConfigurationException, TransformerException {
        DOMSource source = new DOMSource(xmlDoc);
        DOMSource xslSrc = new DOMSource(xslDoc);

        TransformerFactory xformFactory = TransformerFactory.newInstance();
        Transformer transformer = xformFactory.newTransformer(xslSrc);

        java.io.StringWriter sw = new java.io.StringWriter();
        StreamResult outXml = new StreamResult(sw);

        transformer.transform(source, outXml);

        return sw.toString();
    }
}

Related

  1. transformDomDocument(Transformer transformer, Node node, OutputStream os)
  2. transformXmlToString(Document importPackageDocument)
  3. transformXmlToString(Document payload)
  4. transformXMLtoString(Document xmldoc)
  5. xslt(InputStream stylesheet, Document input)