Here you can find the source of xslTransform(Document xmlDoc, Document xslDoc)
Parameter | Description |
---|---|
xmlDoc | Document |
xslDoc | Document |
Parameter | Description |
---|---|
TransformerConfigurationException | an exception |
TransformerException | an exception |
public static String xslTransform(Document xmlDoc, Document xslDoc) throws TransformerConfigurationException, TransformerException
//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(); } }