  In this paper a sponge in $\mathbb{R}^d$ is the attractor of an iterated
function system consisting of finitely many strictly contracting affine maps
whose linear part is a diagonal matrix. A suitable separation condition is
introduced under which a variational formula is proved for the $L^q$ spectrum
of any self-affine measure defined on a sponge for all $q\in\mathbb{R}$. Apart
from some special cases, even the existence of their box dimension was not
proved before. Under certain conditions the formula has a closed form which in
general is an upper bound. The Frostman and box dimension of these measures is
also determined. The approach unifies several existing results and extends them
to arbitrary dimensions. The key ingredient is the introduction of a novel
pressure function which aims to capture the growth rate of box counting
quantities on sponges. We show that this pressure satisfies a variational
principle which resembles the Ledrappier--Young formula for Hausdorff
dimension.
