Sorry; I misread your question. For the question of what templates return, I think we have to go back to the XSLT spec and/or Xalan's source code. I haven't found any indication there that templates are able to return anything other than one of XSLT's native datatypes.
So as far as I can tell, you're out of luck -- if you want something that returns non-XSLT data, it has to be non-XSLT code in an extension function.
