Spectral representations of operators in Hilbert spaces over quaternions and octonions