This second sample consists in three steps:
Compile the XSLT style sheet for all subsequent uses.
Invoke the XSLT engine to convert the input XML document to XSL-FO.
Invoke XMLmind XSL-FO Converter to convert the temporary XSL-FO file generated by second step to RTF.
Excerpts of samples/java/Sample2.java
:
import javax.xml.transform.TransformerFactory; import javax.xml.transform.Transformer; import javax.xml.transform.Templates; import javax.xml.transform.stream.StreamSource; import javax.xml.transform.stream.StreamResult; import org.xml.sax.InputSource; import com.xmlmind.fo.converter.OutputDestination; import com.xmlmind.fo.converter.Converter; ... TransformerFactory factory = TransformerFactory.newInstance(); Templates compiledStylesheet = factory.newTemplates(new StreamSource(xslFile)); Transformer transformer = compiledStylesheet.newTransformer(); foFile = File.createTempFile("sample2_", ".fo"); transformer.transform(new StreamSource(xmlFile), new StreamResult(foFile)); Converter converter = new Converter(); converter.setProperty("outputFormat", "rtf"); converter.setProperty("outputEncoding", "Cp1252"); converter.setProperty("imageResolution", "72"); converter.setProperty("baseURL", xmlFile.toURI().toASCIIString()); InputSource src = new InputSource(foFile.toURI().toASCIIString()); OutputDestination dst = new OutputDestination(rtfFile.getPath()); converter.convert(src, dst); ...
Compile the XSLT style sheet.
| ||||
Transform the XML input file to a temporary output file created in the system-dependant temporary file directory (e.g. | ||||
Create and parameterize a Converter object as explained in Section 2, “Converting an XSL-FO file to RTF”. | ||||
Setting the If the XML input file references graphics files using relative URLs (example: An advanced alternative to specifying a | ||||
Perform the conversion by invoking Converter.convert. |