Java XML Transform createTransformer(final File xsltFile)

Here you can find the source of createTransformer(final File xsltFile)

Description

create Transformer

License

Open Source License

Declaration

static Transformer createTransformer(final File xsltFile)
            throws TransformerException 

Method Source Code

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

import java.io.File;

import java.util.Collections;

import java.util.Map;

import javax.xml.transform.OutputKeys;

import javax.xml.transform.Source;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;

import javax.xml.transform.stream.StreamSource;

public class Main {
    static Transformer createTransformer(final File xsltFile)
            throws TransformerException {
        return createTransformer(xsltFile,
                Collections.<String, String> emptyMap());
    }/*from   w ww .j a  v  a  2 s.  c  o m*/

    /**
     * @param xsltFile The XSLT stylesheet file
     * @param parms XSL parameters to pass to the stylesheet.
     * @return the configured XSLT transformer
     * @throws TransformerException if there is a problem configuring the transformer
     */
    static Transformer createTransformer(final File xsltFile,
            final Map<String, String> parms) throws TransformerException {
        try {
            Source xslSource = new StreamSource(xsltFile);
            TransformerFactory transFact = TransformerFactory.newInstance();
            transFact.setAttribute("indent-number", 2);
            Transformer transformer = transFact.newTransformer(xslSource);
            transformer.setOutputProperty(OutputKeys.INDENT, "yes");
            for (String parm : parms.keySet()) {
                transformer.setParameter(parm, parms.get(parm));
            }
            return transformer;
        } catch (TransformerConfigurationException e) {
            e.printStackTrace();
            throw e;
        }
    }
}

Related

  1. createPrettyTransformer(int indent)
  2. createTransformer()
  3. createTransformer()
  4. createTransformer()
  5. createTransformer()
  6. createTransformerHandler(int indent)
  7. createTXT(Transformer xf, Node doc)
  8. exceptionToString(TransformerException exception, boolean showSystemId)
  9. getDefaultTransformerFactoryThreadLocal()