  In this paper we study relative Riemann-Zariski spaces attached to a morphism
of schemes and generalizing the classical Riemann-Zariski space of a field. We
prove that similarly to the classical RZ spaces, the relative ones can be
described either as projective limits of schemes in the category of locally
ringed spaces or as certain spaces of valuations. We apply these spaces to
prove the following two new results: a strong version of stable modification
theorem for relative curves; a decomposition theorem which asserts that any
separated morphism between quasi-compact and quasi-separated schemes factors as
a composition of an affine morphism and a proper morphism. (In particular, we
obtain a new proof of Nagata's compactification theorem.)
