Java XML Transform transform(String xslSource, Node original)

Here you can find the source of transform(String xslSource, Node original)

Description

transform

License

Open Source License

Declaration

public static Node transform(String xslSource, Node original) 

Method Source Code


//package com.java2s;
import java.io.StringReader;

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

import javax.xml.transform.stream.StreamSource;
import org.w3c.dom.Node;

public class Main {
    public static Node transform(String xslSource, Node original) {
        StringReader sr = new StringReader(xslSource);
        DOMResult result = new DOMResult();
        doTransform(new StreamSource(sr), new DOMSource(original), result);
        return result.getNode();
    }//  w w  w . j  av a  2  s  .c  om

    private static void doTransform(Source xslSource, Source xmlSource, Result xslResult) {
        try {
            TransformerFactory tFactory = TransformerFactory.newInstance();
            Transformer transformer = tFactory.newTransformer(xslSource);
            transformer.transform(xmlSource, xslResult);
        } catch (TransformerFactoryConfigurationError ex) {
            throw new RuntimeException(ex);
        } catch (TransformerException ex) {
            throw new RuntimeException(ex);
        }
    }
}

Related

  1. transform(Source xmlSource, Templates template, Result result, Map parameters)
  2. transform(Source xsl, Source xml, Result result)
  3. transform(String xmlInputFile, String xsltInputFile, OutputStream outputStream)
  4. transform(String xmlInURI, String xslInURI)
  5. transform(String xmlsource, File xsltfile)
  6. transform(Transformer transformer, Node element)
  7. transformar(String xmlOrigen, String xslOrigen)
  8. transformer()
  9. transformerExceptionMsg(TransformerException ex, Node contextNode, String str)