If you have wearing or equipping anything with mending, the XP has a chance to go to them items too. If they're already full durability, you'll gain XP instead. Mending doesn't specifically make XP go to a desired item unless it's the only thing you're wearing/ holding. If the sword has mending as well the levels are going to the sword and if
This page explains the mechanics of the anvil. The anvil is primarily used to repair tools, armor, and weapons, which it can do without stripping their enchantments, unlike the grindstone and crafting table. It can also be used to combine the enchantments of two items, to give an item a custom name, or to crush enemies, mobs or other players that walk beneath it while it is falling, with more
FUvPAd.