Skip to content
Draft
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()
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