Major refactoring and reworking to make functional with XSLT 1.0