Refactorred code for xsl