These commands work as intended:
/execute if entity @p[nbt={ SelectedItemSlot: 0 }]
/execute if entity @p[nbt={ XpLevel: 0 }]
But you must of course have the left-most slot selected for the first one and be level 0 for the second one.
But these ones always fail, even though the syntax is accepted:
/execute if entity @p[nbt={ SelectedItemSlot: 0..8 }]
/execute if entity @p[nbt={ XpLevel: 0.. }]
Given what they select, they should always successfully find all connected players, at least the one executing the commands.
This is not specific to ranged values. This is just how nbt syntax checking behaves, as there is not a deep nbt validation performed during autocomplete, any alphanumeric character and "." (period) are accepted as the first character of a value in a key value pair. The following command is also accepted syntax wise but not 'valid'.
/execute if entity @p[nbt={SelectedItemSlot:foo.bar123}]