Cleaned up the XML path construction to correctly detect the index of elements