If a stylesheet contains any mapping with an occurrence of last, notlast or only, TopLeaf automatically pre-scans the partition document and content read from within included files to determine which elements are the last of their type within a parent element. This pre-scan is triggered even if none of the occurrence specific mappings are applied when the partition is typeset.

The use of tag occurrence is subject to the following restrictions:

  • Mapped elements must share a common parent. This means that custom markers invoked from the $document mapping cannot use occurrence selectors, since these markers are declared outside the context of the document root element.

  • Mapped content must be read directly from the partition document or an included file. Mappings for last, notlast and only may not work as expected within:

  • The determination of the last element for a given type is correct only when an element and its parent are both in the same input document file.

  • It is not possible to map the occurrence of a table row or cell declared within the context of a multi-row table header, or within a cell spanning two or more table rows. Referencing the value of {tag-occurrence} within these contexts can lead to unpredictable results.

  • If a pre-scan is triggered, it is important that the content of the document or any included input files does not change. Any changes made to these files during composition can lead to unpredictable results.


The example below shows how the pre-scan processing can give an incorrect result. The <para> element that is included when processing the &p; entity is not visible to the document pre-scan. This means that it is not possible to map the second (and final) <para> block using a last mapping:

<!DOCTYPE doc [
<!ENTITY p "<para>Second.</para>">