There tend to be two general approaches to this kind of problem. One is to do an absolute computation - something that examines the data and works out how much space is occupied by the first N rows starting at X. The other is incremental, you recursively process the rows keeping a running total as you proceed. Neither is especially easy, I'm afraid.
Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference