Java XML Transform transform(byte[] source, InputStream xslInputStream, File output)

Here you can find the source of transform(byte[] source, InputStream xslInputStream, File output)

Description

Executes the XSLT defined in xslInputStream to transform the source byte array into a file that is written to the descriptor provided by output

License

Open Source License

Parameter

Parameter Description
source The input XSLT byte array to transform
xslInputStream The XSL to do the transformation
output The output transformed XSLT file

Declaration

public static void transform(byte[] source, InputStream xslInputStream, File output)
        throws IOException, TransformerException 

Method Source Code

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

import javax.xml.transform.*;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;
import java.io.*;

public class Main {
    /**//from   w  w  w .  j a  va 2 s .c  o m
     * Executes the XSLT defined in xslInputStream to transform the source byte array into a
     * file that is written to the descriptor provided by output
     * @param source The input XSLT byte array to transform
     * @param xslInputStream The XSL to do the transformation
     * @param output The output transformed XSLT file
     */
    public static void transform(byte[] source, InputStream xslInputStream, File output)
            throws IOException, TransformerException {
        try {
            //Create streams
            ByteArrayInputStream input = new ByteArrayInputStream(source);
            StreamSource xslStream = new StreamSource(xslInputStream);
            FileWriter outputXml = new FileWriter(output);
            StreamSource in = new StreamSource(input);
            StreamResult out = new StreamResult(outputXml);

            //Load our xslt into a transformer template
            TransformerFactory factory = TransformerFactory.newInstance();
            Templates template = factory.newTemplates(xslStream);
            //Get a transformer
            Transformer transformer = template.newTransformer();
            //Execute the transform
            transformer.transform(in, out);

        } catch (IOException | TransformerException e) {
            throw e;
        }
    }
}

Related

  1. newTransformerHandler()
  2. newTransformerHandler()
  3. newTransformerHandler(final SAXTransformerFactory tf)
  4. serializeXML(Transformer transformer, Source input)
  5. transform(byte[] doc, URL xsltUrl, OutputStream out)
  6. transform(File inputFile, Transformer transformer, Writer out)
  7. transform(File xslt_source, File xml_source)
  8. transform(final File sourceXML, final File xslt, final File targetXML)
  9. transform(final Source xml, final Source xslt, final Map params, final Writer err)