Cannot use <xsl:template> here.
Yes, the xsl:template element can only be used as a direct child of xsl:stylesheet.
I have a xsl:template match="/" at the start of my xsl:stylesheet.
It is a best practice to avoid writing your stylesheet as a one big, gigantic template element. If it's too much trouble at this point to divide your template into several smaller ones,
you should try using my code snippet within the xsl:for-each (just the content of my xsl:template, not the whole thing).
It would probably also help a lot if you'd post your XSL document (using the
UBB code tags for decent formatting, please).