Skip to content

Commit 27c3888

Browse files
author
Steve Canny
committed
oxml: improve CT_Tc._tc XPath expression
Under certain circumstances, the w:tbl parent of a w:tc element is not returned first in the result sequence. Add a position qualifier such that only the first ancestor is returned and the return sequence only contains that single value.
1 parent 61b40b1 commit 27c3888

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

docx/oxml/table.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -651,7 +651,7 @@ def _tbl(self):
651651
"""
652652
The tbl element this tc element appears in.
653653
"""
654-
return self.xpath('./ancestor::w:tbl')[0]
654+
return self.xpath('./ancestor::w:tbl[position()=1]')[0]
655655

656656
@property
657657
def _tc_above(self):
@@ -675,7 +675,7 @@ def _tr(self):
675675
"""
676676
The tr element this tc element appears in.
677677
"""
678-
return self.xpath('./ancestor::w:tr')[0]
678+
return self.xpath('./ancestor::w:tr[position()=1]')[0]
679679

680680
@property
681681
def _tr_above(self):

0 commit comments

Comments
 (0)