What is the role of the <toc> element in DITA maps?

The <toc> element in DITA maps serves as a structural component used to explicitly define the location and content of a table of contents (TOC) within the map. It allows authors to specify where the TOC should appear and what topics or sections should be included in the TOC.

Control with the <toc> Element

The <toc> element in DITA maps provides authors with control over the creation and placement of a table of contents. These controls include defining the TOC location, controlling content inclusion, and controlling the TOC directly.

Defining TOC Location

Authors can place the <toc> element within a DITA map to specify where the TOC should appear in the final output. The TOC can be located at the beginning or end of the document or at any other appropriate position within the map.

Content Inclusion

The <toc> element can contain <topicref> elements that reference the topics or sections to be included in the generated TOC. This allows authors to tailor the TOC’s content to the specific needs of the document.

TOC Control

Authors can define attributes within the <toc> element to control aspects of the generated TOC, such as its title, depth (how many levels of subtopics to include), and any filtering criteria.

Example

A DITA map for an academic textbook includes a table of contents at the beginning of the book. The <toc> element can be used to specify the TOC’s location and content.


    <map>
      <title>Academic Textbook</title>
      
      <!-- Define the location and content of the TOC -->
      <toc title="Table of Contents" depth="2">
        <topicref href="ch01-introduction.dita" />
        <topicref href="ch02-history.dita" />
        <topicref href="ch03-philosophy.dita" />
        <!-- Additional topic references for other chapters -->
      </toc>
      
      <!-- Other topic references for the textbook content -->
    </map>
    

In this example:

  • The <toc> element is used to specify the location of the table of contents at the beginning of the textbook.
  • It defines the TOC’s title as “Table of Contents” and sets the depth to include up to two levels of subtopics.
  • The <topicref> elements within the <toc> specify which chapters or sections should be included in the TOC.