Which leads to "is there a way to get the type of an item?"

You can use inspect:type for that [1].

Hope this helps
Christian

[1] https://docs.basex.org/wiki/Inspection_Module#inspect:type