From a quick look I think your
xsl:apply-templates select="*"
should be select="."
you're going one step too deep in the hierarchy. select="*" means select="child::*".
Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference