Last modified on 18 September 2013, at 16:35

XQuery/Installing the XSL-FO module

You may have to work with your eXist system administrator to first enable the XSL-FO XQuery module in order for these examples to run. This can be done by using the following steps.

Step 1: Enable the XSLFO XQuery ModuleEdit

Edit the conf.xml file in the $EXIST_HOME directory. You must un-comment the xslfo module.

<module class="org.exist.xquery.modules.xslfo.XSLFOModule" uri="http://exist-db.org/xquery/xslfo" />

Step 2: Edit the extensions build.properties fileEdit

If your eXist was not built from source the fo module and supporting fop.jar file must also be included in your exist-modules.jar file in all production systems. This can be done by downloading the eXist source and changing the build.properties file setting to be true. For details please see the eXist build instructions

$EXIST_HOME lib/extensions/build.properties or $EXIST_HOME extensions/build.properties

# XSL FO transformations (Uses Apache FOP)
include.module.xslfo = true

If you are running release 1.4 of eXist, the Apache FOP version referenced might no longer be available. If you have a line like the following in your build-properties like this:

Step 3: Update the path to the new XSL-FO zip file in the configuration fileEdit

include.module.xslfo.url = http://apache.cs.uu.nl/dist/xmlgraphics/fop/binaries/fop-0.95-bin.zip

You will find that the Apache project removed the old binaries (not always best practice).

This is the new line this should be replaced with.

include.module.xslfo.url = http://apache.cs.uu.nl/dist/xmlgraphics/fop/binaries/fop-1.0-bin.zip

And additionally change references to the deprecated version in $EXIST_HOME extensions/modules/build.xml to point to the newer version. E.g:

<!-- Apache FOP -->
                <get src="${include.module.xslfo.url}" dest="fop-1.0-bin.zip" verbose="true" usetimestamp="true" />
                <unzip src="fop-1.0-bin.zip" dest="${top.dir}/${lib.user}">
                        <patternset>
                                <include name="fop-1.0/build/fop.jar"/>
                                <include name="fop-1.0/lib/batik-all-*.jar"/>
                                <include name="fop-1.0/lib/xmlgraphics-commons-*.jar"/>
                                <include name="fop-1.0/lib/avalon-*.jar"/>
                        </patternset>
                        <mapper type="flatten"/>
                </unzip>
                <delete file="fop-1.0-bin.zip"/>

Step 4 Download the new XSLFO Zip fileEdit

When you run a build the next time this will download the Apache FOP jar file from the Apache web site.

  cd $EXIST_HOME/extensions/modules
  ant -version
  ant prepare-libs-xslfo

Sample from build log:

prepare-libs-xslfo:
     [echo] Load: true
     [echo] ------------------------------------------------------
     [echo] Downloading libraries required by the xsl-fo module
     [echo] ------------------------------------------------------
      [get] Getting: http://apache.cs.uu.nl/dist/xmlgraphics/fop/binaries/fop-1.0-bin.zip
      [get] To: C:\ws\eXist-1.4dev\extensions\modules\fop-1.0-bin.zip
      [get] ....................................................

      [get] last modified = Thu Jul 31 09:47:44 CDT 2008
    [unzip] Expanding: C:\workspace\exist\extensions\modules\fop-1.0-bin.zip in to C:\workspace\exist\lib\user

Step 5 Verify that the new XSLFO Library is availableEdit

Note that in addition to the fop binary the following jar file is required by the FOP processor.

  $EXIST-HOME/lib/user/xmlgraphics-commons-1.3.1.jar

On UNIX:

 $ sudo cp -v xmlgraphics-commons-1.4.jar $EXIST_HOME/lib/user
 `xmlgraphics-commons-1.4.jar' -> `/usr/local/exist/lib/user/xmlgraphics-commons-1.4.jar'

This can be downloaded from the Apache XML Graphics Commons Distribution Mirror

Step 6 Copy the Java filesEdit

Copy the jar files from $EXIST-HOME/lib/user/fop.jar and the new $EXIST-HOME/lib/extensions/exist-modules.jar on to your production systems. Note you should make sure the source and destination systems are the same version.

If you want to have fop hyphenate your text, put the fop-hyphen.jar into $EXIST-HOME/lib/user/ and restart eXist. fo:blocks with the attribute hyphenate set to true in you fo or xsl file will be hyphenated then if you add a language attribute to the fo:page-sequence. The patterns for many languages are available here: http://sourceforge.net/projects/offo/

Note that your exist-modules.jar file can then be placed on the systems that do not have the source code. There is currently no method to use FOP without downloading the source. Also note that you can verify that your exist-modules.jar file contains the XSLFO classes by running:

You can now check that the jar files are correctly installed in the user libraries directory:

 $ ls -l $EXIST_HOME/lib/user/*.jar

Which returns

total 7480
-rwxrwxrwx 1 root     root       56290 Nov  3  2009 activation-1.1.1.jar
-rw-rw-r-- 1 ec2-user ec2-user 3318083 Jul 12  2010 batik-all-1.7.jar
-rw-rw-r-- 1 ec2-user ec2-user 3079811 Jul 12  2010 fop.jar
-rwxrwxrwx 1 root     root      434812 Nov  3  2009 mail-1.4.2.jar
-rwxrwxrwx 1 root     root      117470 Nov  3  2009 nekohtml-1.9.11.jar
-rw-r--r-- 1 root     root      569113 Nov 12 17:28 xmlgraphics-commons-1.4.jar

Build The ExtensionsEdit

Type the following into the shell:

  $ ./build.{sh|bat} extension-modules

If the build fails with

 "$EXIST_HOME/build/classes" does not exist or is not a directory

, it helps to create the classes folder, afterwards build is successful:

 mkdir $EXIST_HOME/build/classes

Verify that the jar files are in the right positionEdit

  $ jar tf exist-extensions.jar

Or on a windows system you can change the jar file file name to end with .zip, uncompress and check that the xslfo classes are in the exist-modules file.