Login | Register   
RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.


Generate PDF Files Dynamically Using XSL-FO  : Page 2

Learn how to generate Adobe Portable Document Format (PDF) files from XML documents using XSL Formatting Objects (XSL-FO) and a Java Servlet.




Application Security Testing: An Integral Part of DevOps

Step 1: Transform XML Into a .fo File using XSL-FO:
Import the following JAXP packages to perform the transformation process.

   import javax.xml.transform.TransformerFactory;
   import javax.xml.transform.Transformer;
   import javax.xml.transform.stream.StreamSource;
   import javax.xml.transform.stream.StreamResult;
   import javax.xml.transform.TransformerException;
   import  javax.xml.transform.
You start the process by creating a TransformerFactory instance.

   TransformerFactory tfactory =  
Use the TransformerFactory.newTransformer() method to create an instance of the abstract Transformer class. The Transformer class transforms a source tree into a result tree.

You can use the Transformer instance to process XML from a variety of sources and write the transformation output to a variety of sinks. For example, the following code creates a Transformer object and loads it with an XSLT file:

   Transformer transformer=
     (new StreamSource(getServletContext().
You use the Transformer.Transform() method to transform the input XML document into the output .fo file.

   transformer.transform(new StreamSource
   toString()),new StreamResult(new 
   FileOutputStream(filepath )));
The Servlet constructs the file names for the xslPath and xmlPath variables from the Request object. The example passes the filenames and the servlet adds the extension.

   String xslName = request.getParameter("xsl");
   String xmlName = request.getParameter("xml");
   String xslPath = xslName +".xsl";
   String xmlPath = xmlName +".xml";
The Transformer saves the output of the transformation (the .fo file) to the file represented by the filepath variable. That completes the first step.

Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.
Thanks for your registration, follow us on our social networks to keep up-to-date