How to create a Table Of Contents

When creating a template sometimes a table of content is needed. Below you can find the steps to follow in order to insert it in your document:

A. Create the Page Set for the Table of Contents

The first step is to create a simple Page Layout & Page Set for the Table of Contents.

B. Create the Page Set for the actual content

The next step is to add another Page Set for the actual content of the template, and this will be a Repeating Page Set (instructions here). In the attached sample, we iterated through all "cd" nodes.

C. Add the Main Template Content

Once your template structure is finished, add the desired information for each "cd" node, for example, the title of the CD:

  • Go to the Main Content Page Set
  • Insert a field containing the position() function to display the position of the elements;
  • Insert a field containing the "@title" elements that were added in the TOC;
  • Add an id to mark each future TOC topic on the first block of the page set:
    • Go to XML View
    • On the <fo:block> element containing the two fields inserted above, add the fo:id="topicTitle" so you can link them with the items inserted in the Table of Contents.

D. Start working on the table of content section

After adding the desired content, your next step is to define the table of content, which is created in two steps:

  • Adding the topics in the TOC;
  • Adding the references that point to the correct items in the template.

D.1. How to add the topics of the TOC

  1. Go to the first page of your document (select the TOC Page Set);
  2. Go to "Insert" tab in the ribbon and select "Repeating Paragraph";
  3. Select "Create Expression" and insert the node you want to repeat by and then choose "Insert";
  4. In the newly created repeating paragraph, insert a table without borders, containing one row and two columns.

D.2. Add correct TOC references

In order to link the items of your Table Of contents with the pages they point to, you will need to follow these steps:

  1. Switch to "XML View" (View tab -> XML View)
  2. After the <xf:stylesheet/> element add the following lines of code:

    <xfd:attribute-value object="basicLink" attribute="fo:internal-destination" dynamic-value="generate-id(@title)" />
    <xfd:attribute-value object="indexCitation" attribute="fo:ref-index-key" dynamic-value="generate-id(@title)" />
    <xfd:attribute-value object="topicTitle" attribute="fo:id" dynamic-value="generate-id(@title)" />
    <xfd:attribute-value object="topicTitle" attribute="fo:index-key" dynamic-value="generate-id(@title)" />

    Where:
    - Object defines the name of the element to be changed
    - Attribute is the name of the property that will be modified
    - Dynamic-value is the new value assigned to each object.
    Note: The generate-id function is used to generate an ID for each particular element. We used the “@title” attribute because in our case we want to generate a Table of Contents for the “@title” elements of our <CD> nodes;

With regards to the elements modified, the following information should be known:

  • fo:internal-destination - Specifies the destination flow object within the formatting object tree.
  • fo:ref-index-key - Specifies the "index-key" of objects in the formatting object tree.
  • fo:id - An identifier unique within all objects in the result tree with the fo: namespace. It allows references to this formatting object by other objects.
  • fo:index-key - Associates an index key with the formatting object on which it is specified.

D.3. Design the Table of Contents

  1. Add the numbering of the TOC elements
    1. Go back to Design View
    2. Click on the area of the first column of the table
    3. Go to Insert tab in the Ribbon and select the Field button
    4. Insert the following expression in order to give numbering to your elements:
      concat(position(),'.')
    5. The expression above will concatenate the position of the element in the list with a “.”, to obtain the numbering in the following format: 1. , 2.,  3. etc.


  2. Add the topics of the Table of Contents
    1. Click on the area of the second column of the table
    2. Go to the View tab in the Ribbon and select “XML View” (use Auto Format feature if needed);
    3. Inside the <fo:block> element insert a basic link element that contains two elements: an fo:leader , and an fo:index-page-citation-list.
      The content of the <fo:basic-link> element should look like this:                                      <fo:basic-link id="basicLink">
           <fo:leader leader-pattern="dots" leader-length="50%"/>
           <fo:index-page-citation-list>
                <fo:index-key-reference font-weight="bold" id="indexCitation"/>
           </fo:index-page-citation-list>
      </fo:basic-link>

      Where:
      1. The <fo:basic-link> element is necessary to create a link. it should reference the before created attribute id="basicLink"; 
      2.  The <fo:leader> represents the line between the topic subject and the topic page.
        Attributes: leader-pattern="dots" , leader-length="50%" ;
      3. The <fo:index-page-citation-list> element creates the numbering. It requires a child <fo:index-key-reference> element to reference the index keys of each element. On the <fo:index-key-reference> add the id="indexCitation"

    4. Go back to Design View, and add the dynamic field that represents the topic subject:
      1. Click in the second column of the table
      2. Press "Home" to move the caret before the dotted area
      3. Add the field containing the elements you wanted to be contained in the TOC. In our case, it is "@title".

Optional Style Adjustments:

- Remove additional space at the end of the repeating paragraph:

  1. Click at the end of the table:
  2. Press "Delete"

- Add formatting.

Attached you will find two samples, one containing the behavior described above and one modified to display the TOC in a justified manner.

Have more questions? Submit a request

Comments

Powered by Zendesk