Example: On-the-Fly Table of Contents

Top Previous Topic Next Topic  Print this topic

In this example we will use the special job-info() function to create and format a table of contents.

 

How to Use the job-info() Function

 

We'll start with some very generic information which should work when included in any DAL job.

 

A job info document looks like any XFD or XSLT document, with the only difference being the input xml, which has to point to job-info().

 

<xfj:document id="toc">

       <xfj:external-content src="url(toc_xfd_url)"/>

       <xfj:input-xml src="job-info()"/>

</xfj:document>

 

The toc_xfd_url represents the URL or base64 bytes of the template (XSLT or XFD) to use when rendering the job info file.

 

The XFD/XSL template must reference the fields in the job info document. In the following example, we are selecting all documents except this one (we are excluding the 'toc' id from the resulting XML node set):

 

<xfd:block-repeat xpath="/xfj:job-info/xfj:document-info[@id != 'toc']">

       <fo:block text-align-last="justify">

               <xfd:field xpath="@id"/> - <xfd:field xpath="@title"/>

               <fo:leader leader-pattern="dots"/>

               <xfd:field xpath="@page"/>

       </fo:block>

</xfd:block-repeat>

 

The output of the above template will look like:

 

doc1 - Title of Doc 1...................................3

doc2 - Title of Doc 2...................................7

doc3 - Title of Doc 3..................................10

 

The structure of the in-memory job info file is described here.

 

Full Job Example with Table of Contents

 

We will build upon the job used in the previous examples. We will both add the job info document and suppress displaying the overlay for it by adding a new rule to the xfj:overlay element to exclude the document with the id 'toc'.

 

In this sample, we won't want the document id to be visible, so the table of contents will look like this:

 

 

Note: Changing the id of a document will require changing all the rules that reference it as well.

 

This is what the full DAL job looks like:

 

<?xml version="1.0" encoding="utf-8"?>

<xfj:job xmlns:xfj="http://www.ecrion.com/xfj/1.0">

 

       <xfj:output mime-type="application/pdf"/>

 

       <xfj:overlay id="Header" z-index="1">

               <xfj:apply-rules>

                       <xfj:match rule="all" />

                       <xfj:match rule="exclude(toc)" />

               </xfj:apply-rules>

               <xfj:external-content src="url(Overlay.fo)" />

       </xfj:overlay>

 

       <xfj:document id="toc">

               <xfj:external-content src="TOC.xfd"/>

               <xfj:input-xml src="job-info()"/>

       </xfj:document>

 

       <xfj:document id="doc2" title="Current Superannuation">

               <xfj:external-content src="InputPDF.pdf"/>

       </xfj:document>

 

       <xfj:document id="doc3" title="Your Funds">

               <xfj:apply-local-template src="InputXFD.xfd"/>

               <xfj:external-content src="data.xml"/>

       </xfj:document>        

 

</xfj:job>

 

 

All the files referenced in this example can be found in the XML Samples folder.