Negative invariant: every r:id referenced on a slide's a:hlinkClick must have a matching <Relationship Id='...'/> in the slide's rels file, and the rels file must not carry duplicate Ids.
Library verdicts: python-pptx: — pptxjs: —
| Feature id | pptx/relationship-orphan-detection |
|---|---|
| Format | pptx |
| Category | references |
| Spec | ecma-376-5-part-2 § 9.3 pr:Relationship |
| ID / part | Predicate | XPath | python-pptx | pptxjs |
|---|---|---|---|---|
slide-hlinkclick-has-ridppt/slides/slide1.xml | match = ^1(\.0+)?$Exactly one a:hlinkClick with an r:id must be present on slide 1. | count(//a:hlinkClick[@r:id]) | — | — |
slide-rel-count-is-1-hyperlinkppt/slides/_rels/slide1.xml.rels | match = ^1(\.0+)?$The slide's rels file must carry exactly one hyperlink Relationship. | count(//pr:Relationship[@Type='http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink']) | — | — |
slide-rel-ids-uniqueppt/slides/_rels/slide1.xml.rels | absentRelationship Ids must be unique within the rels file; any duplicate would be selected by this XPath. | //pr:Relationship[@Id = preceding-sibling::pr:Relationship/@Id] | — | — |
slide-hyperlink-rel-is-externalppt/slides/_rels/slide1.xml.rels | equal = ExternalThe hyperlink relationship in this fixture is external; it must carry TargetMode='External'. | string(//pr:Relationship[@Type='http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink']/@TargetMode) | — | — |
No render assertions declared.
scripts/gen_relationship_orphan_detection_pptx.py
#!/usr/bin/env python3
"""Generate ``fixtures/pptx/relationship-orphan-detection.pptx``.
A minimal presentation with exactly one external-URL hyperlink on slide 1.
Designed to satisfy ``pptx/relationship-orphan-detection``.
.. versionadded:: 2026.05.0
"""
from __future__ import annotations
import datetime as _dt
from pathlib import Path
from pptx import Presentation
from pptx.util import Inches
_REPO_ROOT = Path(__file__).resolve().parent.parent
_OUT = _REPO_ROOT / "fixtures" / "pptx" / "relationship-orphan-detection.pptx"
_REPRODUCIBLE_DT = _dt.datetime(2000, 1, 1, 0, 0, 0)
def main() -> int:
prs = Presentation()
slide = prs.slides.add_slide(prs.slide_layouts[5])
textbox = slide.shapes.add_textbox(Inches(1), Inches(2), Inches(6), Inches(1))
run = textbox.text_frame.paragraphs[0].add_run()
run.text = "Resolved external hyperlink"
run.hyperlink.address = "https://example.com/no-orphan"
_OUT.parent.mkdir(parents=True, exist_ok=True)
prs.save(_OUT, zip_date_time=_REPRODUCIBLE_DT)
print(_OUT)
return 0
if __name__ == "__main__":
raise SystemExit(main())
{
"$schema": "../manifest.schema.json",
"id": "pptx/relationship-orphan-detection",
"title": "Relationship orphan detection (pptx)",
"format": "pptx",
"category": "references",
"summary": "Negative invariant: every r:id referenced on a slide's a:hlinkClick must have a matching <Relationship Id='...'/> in the slide's rels file, and the rels file must not carry duplicate Ids.",
"spec": {
"source": "ecma-376-5-part-2",
"clause": "9.3",
"element": "pr:Relationship",
"rnc_reference": "spec/ecma-376-5/part-2/rnc/opc-relationships.rnc",
"xsd_reference": "spec/ecma-376-5/part-2/xsd/opc-relationships.xsd",
"notes": "Part-2 OPC invariants applied at slide scope. The fixture carries exactly one external-URL hyperlink on slide 1. The assertions pin both sides of the link: slide1.xml references one a:hlinkClick with an r:id, and slide1.xml.rels contains exactly one hyperlink Relationship with a matching Id."
},
"fixtures": {
"machine": "pptx/relationship-orphan-detection"
},
"generator": {
"python": "scripts/gen_relationship_orphan_detection_pptx.py"
},
"assertions": [
{
"id": "slide-hlinkclick-has-rid",
"part": "ppt/slides/slide1.xml",
"namespaces": {
"a": "http://schemas.openxmlformats.org/drawingml/2006/main",
"r": "http://schemas.openxmlformats.org/officeDocument/2006/relationships"
},
"xpath": "count(//a:hlinkClick[@r:id])",
"must": "match",
"value": "^1(\\.0+)?$",
"description": "Exactly one a:hlinkClick with an r:id must be present on slide 1."
},
{
"id": "slide-rel-count-is-1-hyperlink",
"part": "ppt/slides/_rels/slide1.xml.rels",
"namespaces": {
"pr": "http://schemas.openxmlformats.org/package/2006/relationships"
},
"xpath": "count(//pr:Relationship[@Type='http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink'])",
"must": "match",
"value": "^1(\\.0+)?$",
"description": "The slide's rels file must carry exactly one hyperlink Relationship."
},
{
"id": "slide-rel-ids-unique",
"part": "ppt/slides/_rels/slide1.xml.rels",
"namespaces": {
"pr": "http://schemas.openxmlformats.org/package/2006/relationships"
},
"xpath": "//pr:Relationship[@Id = preceding-sibling::pr:Relationship/@Id]",
"must": "absent",
"description": "Relationship Ids must be unique within the rels file; any duplicate would be selected by this XPath."
},
{
"id": "slide-hyperlink-rel-is-external",
"part": "ppt/slides/_rels/slide1.xml.rels",
"namespaces": {
"pr": "http://schemas.openxmlformats.org/package/2006/relationships"
},
"xpath": "string(//pr:Relationship[@Type='http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink']/@TargetMode)",
"must": "equal",
"value": "External",
"description": "The hyperlink relationship in this fixture is external; it must carry TargetMode='External'."
}
]
}
No rendered reference is available for this case.