Could you please show some real input and output? I can't figure out what these x's and y's are supposed to represent. Are you literally putting x's in the cells of your output table, or does x represent something else?
Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference