Java XML Transform transform(InputStream xsltInputStream, InputStream xmlInputStream, OutputStream outputStream, Map parameterMap)

Here you can find the source of transform(InputStream xsltInputStream, InputStream xmlInputStream, OutputStream outputStream, Map parameterMap)

Description

transform

License

Open Source License

Declaration

public static boolean transform(InputStream xsltInputStream, InputStream xmlInputStream,
            OutputStream outputStream, Map<String, Object> parameterMap) 

Method Source Code


//package com.java2s;
/* /*  w w  w  .ja v  a 2 s . com*/
 * Copyright (c) 2015-present Jan To?ovsk? <jan.tosovsky.cz@gmail.com>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

import java.io.InputStream;
import java.io.OutputStream;
import java.util.Map;
import java.util.Map.Entry;
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.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;

public class Main {
    public static boolean transform(InputStream xsltInputStream, InputStream xmlInputStream,
            OutputStream outputStream, Map<String, Object> parameterMap) {

        boolean result = false;

        try {

            Source source = new StreamSource(xsltInputStream);
            Transformer transformer = TransformerFactory.newInstance().newTemplates(source).newTransformer();

            for (Entry<String, Object> entry : parameterMap.entrySet()) {
                transformer.setParameter(entry.getKey(), entry.getValue());
            }

            transformer.transform(new StreamSource(xmlInputStream), new StreamResult(outputStream));

            result = true;

        } catch (TransformerException | TransformerFactoryConfigurationError e) {
        }

        return result;
    }
}

Related

  1. transform(final Source xml, final Source xslt, final Map params, final Writer err)
  2. transform(InputStream styleSheet, InputStream xml, Writer out)
  3. transform(InputStream styleSheet, InputStream xml, Writer out)
  4. transform(InputStream xmlStream, InputStream xslStream, OutputStream outputStream)
  5. transform(InputStream xslis, InputStream xmlis, OutputStream xmlos)
  6. transform(javax.xml.transform.Source source, javax.xml.transform.Result result, boolean indent)
  7. transform(Reader source, Writer result, String style)
  8. transform(SOAPPart part)
  9. transform(Source source, Result res)