How to change the item type of an item in a player's inventory but keeping its NBT tag in 1.17?

Solution 1:

Item modifiers are not for changing the type of an item. Instead, a loot table should be used that copies the item NBT from the old item.

Such a loot table would look like this:

{
  "type": "minecraft:generic",
  "pools": [
    {
      "rolls": 1,
      "entries": [
        {
          "type": "minecraft:item",
          "name": "minecraft:elytra",
          "functions": [
            {
              "function": "minecraft:copy_nbt",
              "source": "this",
              "ops": [
                {
                  "source": "Inventory[{Slot:102b}].tag",
                  "target": "{}",
                  "op": "merge"
                }
              ]
            }
          ]
        }
      ]
    }
  ]
}

A command to do this would look like:

loot replace entity @s armor.chest 1 loot LOOT_TABLE_ID