Listing 1
<xsl:stylesheet version="1.0"
xlmns:xsl="http://www.w3.org/1999/XSL/Transform"
xlmns:fo="http://www.w3.org/1999/XSL/Format">
<xsl:template match="page">
<xsl:processing-instruction name="cocoon-format">type=
"text/xslfo"
<fo:root xlmns:fo="http://www.w3.org/1999/XSL/Format">
<fo:layout-master-set>
<fo:simple-page-master master-name="tss_Page1"
page-width="297mm" page-height="240mm"
margin-top="0.5in" margin-bottom="0.5in"
margin-left="0.5in" margin-right="0.5in" >
<fo:region-before extent="5.0in"/>
<fo:region-body margin="50mm 00mm 50mm
0mm"/>
<fo:region-after extent="1.0in"/>
</fo:simple-page-master>
</fo:layout-master-set>
<fo:page-sequence master-reference ="tss_Page1">
<fo:flow flow-name="xsl-region-body">
<fo:block text-align="center"> Hi There!
</fo:block>
<fo:block text-align="center"> Hello World!
</fo:block>
</fo:flow>
</fo:page-sequence>
</fo:root>
</xsl:template>

Listing 2
<fo:table border-spacing="3in" text- align="center">
<fo:table-column column-number="1" column-
width="200mm" />
<fo:table-body>
<fo:table-row text-align="left">
<fo:table-cell border-style="solid" border-
width="0mm" background-color="#FFFFFF">
<fo:block text-align="center">
Hello World!
</fo:block>
</fo:table-cell>
</fo:table-row>
</fo:table-body>
</fo:table

Listing 3
<xsl:stylesheet version="1.0"
xlmns:xsl="http://www.w3.org/1999/XSL/Transform"
xlmns:fo="http://www.w3.org/1999/XSL/Format">
<xsl:template match="page">
<xsl:processing-instruction name="cocoon-format">type=
"text/xslfo"</xsl:processing-instruction>
<fo:root xlmns:fo="http://www.w3.org/1999/XSL/Format">
<fo:layout-master-set>
<fo:simple-page-master
master-name="tss" page-width="297mm" page-
height="240mm" margin-top="0.5in" margin-
bottom="0.5in" margin-left="0.5in" margin-
right="0.5in" >
<fo:region-before extent="5.0in"/>
<fo:region-body margin="50mm 00mm 50mm
0mm"/>
<fo:region-after extent="1.0in"/>
</fo:simple-page-master>
</fo:layout-master-set>
<fo:page-sequence master-reference ="tss">
<fo:flow flow-name="xsl-region-body">
<fo:table border-spacing="3in" text-
align="center">
<fo:table-column column-number="1" column-
width="200mm" />
<fo:table-body>
<fo:table-row text-align="left">
<fo:table-cell border-style="solid" border-
width="0mm" background-color="#FFFFFF">
<fo:block text-align="center">
<fo:table border="1pt solid black" >
<fo:table-column column-number="1"
column-width="72mm" />
<fo:table-column column-number="2"
column-width="120mm" />
<fo:table-body>
<xsl:apply-templates>
</fo:table-body>
</fo:table>
</fo:block>
</fo:table-cell>
</fo:table-row>
</fo:table-body>
</fo:table>
</fo:flow>
</fo:page-sequence>
</fo:root>
</xsl:template>

Listing 4
// Create an instance of TransformerFactory class.
TransformerFactory tfactory=
TransformerFactory.newInstance();
// Create an instance of Transformer class.
// The input to Transformer instance is the xsl file.
// Here xslFilePath refers to the absolute file path of
// Subscription.xsl file.
Transformer transformer=
tfactory.newTransformer (
new StreamSource(xslFilePath));
// Transform the dynamically created xml file
// (xmlString) which is of type java.lang.String.
// Output is an intermediate ".fo" file, Subscription.fo.
// [ "foFile" should refer to the absolute path of
// Subscription.fo file ]
transformer.transform (new StreamSource(xmlString),new StreamResult(foFile));

Listing 5
// Create an InputSource that takes the
// "Subscription.fo" file as input.
InputSource fopfile = new InputSource(new FileInputStream(foFile));
Invoke the method
renderPDF(InputSource in, OutputStream out);
public static void renderPDF (InputSource in, OutputStream out) throws Exception
{
//Set the parser type.
System.setProperty("org.xml.sax.parser",
"org.apache.xerces.parsers.SAXParser");
// Instantiate the org.apache.fop.apps.Driver class
// and pass the InputSource and Servlet
// OutputStream objects.
Driver driver = new Driver(in, out);
driver.setLogger(log);
// Set the renderer type to PDF.
driver.setRenderer(Driver.RENDER_PDF);
driver.addElementMapping("org.apache.fop.fo.StandardElement
Mapping"); driver.addElementMapping("org.apache.fop.svg.SVGElementMapping");
// Invoke the run() method.
driver.run();
// Flush the OutputStream.
out.flush();
}