Sorry, your code fragment looked superficially like XSLT and you asked the question on an XSLT forum so I assumed the question was about XSLT.
If you're using some different language then you're on your own, mate.
Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference