The interrelation of hard X-ray (HXR) emitting sources and the underlying physics of electron acceleration and transport presents one of the major questions in high-energy solar flare physics. Spatially resolved observations of solar flares often demonstrate the presence of well-separated sources of bremsstrahlung emission, so-called coronal and footpoint sources. Using spatially resolved X-ray observations by the Reuven Ramaty High Energy Solar Spectroscopic Imager (RHESSI) and recently improved imaging techniques, we investigate in detail the spatially resolved electron distributions in a few well-observed solar flares. The selected flares can be interpreted as having a standard geometry with chromospheric HXR footpoint sources related to thick-target X-ray emission and the coronal sources characterised by a combination of thermal and thin-target bremsstrahlung. Using imaging spectroscopy techniques, we deduce the characteristic electron rates and spectral indices required to explain the coronal and footpoint X-ray sources. We found that, during the impulsive phase, the electron rate at the looptop is several times (a factor of 1.7−8) higher than at the footpoints. The results suggest that a sufficient number of electrons accelerated in the looptop explain the precipitation into the footpoints and imply that electrons accumulate in the looptop. We discuss these results in terms of magnetic trapping, pitch-angle scattering, and injection properties. Our conclusion is that the accelerated electrons must be subject to magnetic trapping and/or pitch-angle scattering, keeping a fraction of the population trapped inside the coronal loops. These findings put strong constraints on the particle transport in the coronal source and provide quantitative limits on deka-keV electron trapping/scattering in the coronal source.