Among the stationary configurations of the Hamiltonian of a classical O$(n)$ lattice spin model, a class can be identified which is in one-to-one correspondence with all the the configurations of an Ising model defined on the same lattice and with the same interactions. Starting from this observation it has been recently proposed that the microcanonical density of states of an O$(n)$ model could be written in terms of the density of states of the corresponding Ising model. Later, it has been shown that a relation of this kind holds exactly for two solvable models, the mean-field and the one-dimensional $XY$ model, respectively. We apply the same strategy to derive explicit, albeit approximate, expressions for the density of states of the two-dimensional $XY$ model with nearest-neighbor interactions on a square lattice. The caloric curve and the specific heat as a function of the energy density are calculated and compared against simulation data, yielding a very good agreement over the entire energy density range. The concepts and methods involved in the approximations presented here are valid in principle for any O$(n)$ model.