Example usage for org.jdom2.transform XSLTransformer XSLTransformer

List of usage examples for org.jdom2.transform XSLTransformer XSLTransformer

Introduction

In this page you can find the example usage for org.jdom2.transform XSLTransformer XSLTransformer.

Prototype

public XSLTransformer(Document stylesheet) throws XSLTransformException 

Source Link

Document

This will create a new XSLTransformer by reading the stylesheet from the specified Document.

Usage

From source file:cz.muni.fi.pb138.scxml2voicexmlj.XmlHelper.java

/**
 * Use provided XSL transform from resources to transform {@code source}
 */// w  w  w . j a v a  2 s  .c  om
public Element transformElement(Element source, String stylesheetName) {
    try (InputStream stylesheet = getClass().getResourceAsStream(stylesheetName)) {
        XSLTransformer transformer = new XSLTransformer(stylesheet);
        return (Element) transformer.transform(asList((Content) source)).get(0);
    } catch (IOException | XSLTransformException e) {
        throw new RuntimeException(e);
    }
}

From source file:org.goobi.production.export.ExportXmlLog.java

License:Open Source License

/**
 * This method transforms the xml log using a xslt file and opens a new window with the output file
 * /*from w  ww. ja v  a  2 s .c o  m*/
 * @param out ServletOutputStream
 * @param doc the xml document to transform
 * @param filename the filename of the xslt
 * @throws XSLTransformException
 * @throws IOException
 */

public void XmlTransformation(OutputStream out, Document doc, String filename)
        throws XSLTransformException, IOException {
    Document docTrans = new Document();
    if (filename != null && filename.equals("")) {
        XSLTransformer transformer;
        transformer = new XSLTransformer(filename);
        docTrans = transformer.transform(doc);
    } else {
        docTrans = doc;
    }
    Format format = Format.getPrettyFormat();
    format.setEncoding("utf-8");
    XMLOutputter xmlOut = new XMLOutputter(format);

    xmlOut.output(docTrans, out);

}

From source file:org.jumpmind.metl.core.runtime.component.XsltProcessor.java

License:Open Source License

public static String getTransformedXml(String inputXml, String stylesheetXml, String xmlFormat,
        boolean omitXmlDeclaration) {
    StringWriter writer = new StringWriter();
    SAXBuilder builder = new SAXBuilder();
    builder.setXMLReaderFactory(XMLReaders.NONVALIDATING);
    builder.setFeature("http://xml.org/sax/features/validation", false);
    try {//from   ww w .  j av a2  s .  co  m
        Document inputDoc = builder.build(new StringReader(inputXml));
        StringReader reader = new StringReader(stylesheetXml);
        XSLTransformer transformer = new XSLTransformer(reader);
        Document outputDoc = transformer.transform(inputDoc);
        XMLOutputter xmlOutput = new XMLOutputter();
        Format format = null;
        if (xmlFormat.equals(COMPACT_FORMAT)) {
            format = Format.getCompactFormat();
        } else if (xmlFormat.equals(RAW_FORMAT)) {
            format = Format.getRawFormat();
        } else {
            format = Format.getPrettyFormat();
        }

        format.setOmitDeclaration(omitXmlDeclaration);
        xmlOutput.setFormat(format);
        xmlOutput.output(outputDoc, writer);
        writer.close();
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    return writer.toString();
}