docling icon indicating copy to clipboard operation
docling copied to clipboard

JATS: section headings with a <label> lose their <title>

Open MaiAditya opened this issue 3 weeks ago • 0 comments

Bug

In the JATS backend, a <sec> that has both a <label> and a <title> gets only the label as its heading. The title text is lost. The committed test file tests/data/jats/ptag100.xml shows it: its groundtruth has ## 1., ## 2., ### 2.1. and #### 2.1.1. as headings, while the XML has the titles "Introduction", "Analysis of the system", "Basic formulations: Hamiltonian and invariant" and "Setup of the Hamiltonian".

Cause: the headings are built from child.xpath("title|label")[0]. XPath returns the nodes in document order, and JATS puts <label> before <title>, so the first node is the label. The same pattern is used for ref-list headings and for structured abstract sections.

Steps to reproduce

from io import BytesIO

from docling.datamodel.base_models import DocumentStream
from docling.document_converter import DocumentConverter

JATS = b"""<!DOCTYPE article PUBLIC "-//NLM//DTD JATS (Z39.96) Journal Archiving and Interchange DTD v1.2 20190208//EN" "JATS-archivearticle1.dtd">
<article>
<front><article-meta><title-group><article-title>T</article-title></title-group></article-meta></front>
<body>
<sec><label>1.</label><title>Introduction</title><p>Intro text.</p>
<sec><label>1.1.</label><title>Background</title><p>Background text.</p></sec></sec>
</body></article>"""

doc = DocumentConverter().convert(
    DocumentStream(name="t.nxml", stream=BytesIO(JATS))
).document
print(doc.export_to_markdown())

Actual

# T

## 1.

Intro text.

### 1.1.

Background text.

Expected

# T

## 1. Introduction

Intro text.

### 1.1. Background

Background text.

Versions

  • docling main @ 896f2fd9 (2.149.0), docling-core 2.106.0
  • Python 3.12.7, macOS 15.7.3

I can open a PR for this.

MaiAditya avatar Nov 08 '26 16:11 MaiAditya