Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions packtools/sps/models/v2/article_xref.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,3 +155,34 @@ def xrefs_by_rid(self):
response.setdefault(rid, [])
response[rid].append(xref_data)
return response

def all_xrefs(self):
"""Returns a list of data dicts for all <xref> elements in the document."""
result = []
for xref_node in self.xml_tree.xpath(".//xref"):
xref = Xref(xref_node)
data = xref.data
data["xml"] = xref.xml
# Check if element has text content (for self-closing detection)
content = " ".join(xref_node.xpath(".//text()")).strip()
Copy link

Copilot AI Apr 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all_xrefs() recomputes text content with xref_node.xpath('.//text()') even though Xref.data already includes a content field built from the same XPath. Reusing data["content"].strip() would avoid duplicated work and keep the source of truth for extracted xref content in one place.

Suggested change
content = " ".join(xref_node.xpath(".//text()")).strip()
content = (data.get("content") or "").strip()

Copilot uses AI. Check for mistakes.
data["has_text_content"] = bool(content)
result.append(data)
return result

def all_ids(self):
"""Returns a set of all @id attribute values in the document."""
ids = set()
for node in self.xml_tree.xpath(".//*[@id]"):
id_val = node.get("id")
if id_val:
ids.add(id_val)
return ids

def transcript_sections(self):
"""Returns a list of @id values for <sec sec-type='transcript'> elements."""
result = []
for node in self.xml_tree.xpath('.//sec[@sec-type="transcript"]'):
sec_id = node.get("id")
if sec_id:
result.append(sec_id)
return result
Loading
Loading