global

def row_match_cells_to_headers(row)

def row_match_cells_to_headers(row)
  row.map do |header, cell|
    header_xp = XPath.ancestor(:table)[1].descendant(:tr)[1].descendant(:th)[XPath.string.n.is(header)]
    XPath.descendant(:td)[
      XPath.string.n.is(cell) & header_xp.boolean & XPath.position.equals(header_xp.preceding_sibling.count.plus(1))
    ]
  end.reduce(:&)
end