Minecraft wiki entry for Mending, associated text: Any items with Mending in the player's main hand, offhand, or armor slots that are not at maximum durability are repaired by experience orbs collected from any source. The rate of repair is two durability per point of experience contained in the orb.
Experience in the orb is deducted by one point for every two durability points repaired. For example, one durability point repaired doesn't take any experience away from the orb.
Experience left in the orb is added to the player's total experience gauge as normal.
If multiple equipped items have the enchantment and need to be repaired, one is randomly selected for each experience orb collected. No item or location has priority for repair.
Mending does not select items that are already fully repaired. For example, if the player has a fully repaired helmet and a damaged chest plate, leggings, and boots, only the latter 3 are considered in the random chance to be repaired.
Durability doesn't affect which item is chosen at random. For example, a sword that is one durability point away from being fully repaired has an equal chance of being chosen as a pickaxe that is almost broken, even if this means less experience would be used to repair the sword.
Only one of these items is repaired for each experience orb collected. This means that any experience left on the orb is not used to repair other items and is instead added to the player's total experience gauge as normal.