XQuery Makeover to Improve Testability with XSpec

Refactor main module to create a testable library function