You say: My xml file looks like this:
<a...>
<a...>
<a...>
...
But it can't do, that wouldn't be well formed. There must be an outer element, let's call it B. If you want to create the element x just once, then create it in the template rule with match="B".
Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference