It's not a question of namespaces. It's a question of which programming language you are using. Your code is written in WD-xsl, a no-longer-supported Microsoft variant of an early working draft of what later became XSLT. There's no earthly reason to write code in that language any more: write in XSLT instead. Apart from anything else, your code is written half in WD-xsl and half in JavaScript, whereas if you used XSLT you could do it all in a single language without any script.
Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference