http://zorba.io/modules/xsl-fo

View as XML or JSON.

This module converts XSL-FO documents to various formats such as PDF, EPS, PCL, AFP, Text, PNG, Postscript, RTF, and TIFF. For instance, the following example converts a simple XSL-FO document to PDF:

import module namespace fop = "http://zorba.io/modules/xsl-fo";
 import module namespace file = "http://expath.org/ns/file";
 declare namespace fo = "http://www.w3.org/1999/XSL/Format";
 let $xsl-fo := <fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
   <fo:layout-master-set>
     <fo:simple-page-master master-name="my-page">
       <fo:region-body margin="1in"/>
     </fo:simple-page-master>
   </fo:layout-master-set>
   <fo:page-sequence master-reference="my-page">
     <fo:flow flow-name="xsl-region-body">
       <fo:block>Hello, world!</fo:block>
     </fo:flow>
   </fo:page-sequence>
  </fo:root>
 let $pdf := fop:generator($fop:PDF, $xsl-fo)
 return file:write-binary("simple.pdf", $pdf)

This module uses Apache-FOP to generate content from an XSL-FO document. See the Apache FOP documentation for further information.

Note for Windows users: On Windows, this module won't work out of the box, since this module uses Java. But the Java VM dll is not in the system path by default. To make this module work, you need to add the directory where the jvm.dll is located to the system path. This dll is located at JRE_DIR\bin\client. On a standard installation, this would be something a path like "C:\Program Files\Java\jre6\bin\client".

Function Summary

generator ($output-format as xs:string, $xsl-fo-document as node()) as xs:base64Binary

The generator function takes an XSL-FO document as input and generates output in the format given as input.

Functions

generator#2

declare  function xsl-fo:generator($output-format as xs:string, $xsl-fo-document as node()) as xs:base64Binary
The generator function takes an XSL-FO document as input and generates output in the format given as input. The output format can be given as a MIME type - for example "application/pdf" - or one of the predefined variables can be used - like $xsl-fo:PDF. Please refer to the Apache FOP documentation for supported output formats. Apache FOP does not support 100% of the XSL-FO standard. Please consult the official documentation for further information. This function tries to find the needed Java libraries itself.

On a Mac OS X computer, it should be sufficient to install Apache FOP via Mac Ports.

On Ubuntu it should be sufficient to install the fop packages via apt-get.

On Windows, the classpath needs to be set manually using generator#3.

This function tries to find the jar files via environment variables. The user can set the variable FOP_HOME to the root directory of an Apache FOP distribution. If you have all JAR files in the same directory, you can set the environment variable FOP_LIB_DIR to this directory.

Parameters

output-format as xs:string
The mime of the output format, to tell Apache FOP which kind of document it should create.
xsl-fo-document as node()
The XSL-FO document from which the output should be generated.

Returns

xs:base64Binary
The generated output document.

Variables

$xsl-fo:AFP as xs:string
The mime type of IBMs AFP format (application/x-afp).
$xsl-fo:EPS as xs:string
The mime type of the EPS format (application/postscript).
$xsl-fo:PCL as xs:string
The mime type of the PCL format (application/x-pcl).
$xsl-fo:PDF as xs:string
The mime type of the PDF format (application/pdf).
$xsl-fo:PLAIN_TEXT as xs:string
The mime type for plain text files (text/plain).
$xsl-fo:PNG as xs:string
The mime type of the PNG format (image/png).
$xsl-fo:POSTSCRIPT as xs:string
The mime type of the postscript format (application/postscript).
$xsl-fo:RTF as xs:string
The mime type of the RTF format (application/rtf).
$xsl-fo:TIFF as xs:string
The mime type of TIFF format (application/tiff).