iptables marking based on routing table?

Is it possible to mark traffic based on routing table? Let’s say I need to mark traffic which is destined to host XYZ and while going to XYZ it’s passing some host X along the way.
I want to mark packets if the traffic passed host X, if not I don’t want to mark it. So basically I want to mark, based on “passing hosts” rather than “destined hosts”.

Yes it is possible to mark packet based on routing table.

/ip firewall mangle> add routing-table=name of the table ...