If you have floats, you can use inset page numbers with spans and an appropriate
stylesheet.

But fundamentally what you're running into, and I don't know how you avoid it if you
insist on XML/XHTML, is that books simply aren't well-formed in the way that
XML defines and requires. You can't embed everything 100% in all its containers.

Page numbers are a reflection of this problem, because conceptually they are
boundaries between page elements. But page elements simply aren't well-formed
because their tops and bottoms can cut right through paragraphs (and everything
within which paragraphs are embredded.)

I think what happened to some devices is that they had to decide between
supporting HTML and XHTML, and since writers can't be constrained to
create well-formed XML documents (nor should they be), the devices
 had to choose HTML.