Workflow templates are necessary for various different Web Service related tasks such as encoding business rules in a B2B application, specifying domain knowledge in a scientific Grid application, and defining preferences for users that interact with Web Services. Abstract activities in templates can be used to specify the features of a required service and concretes service can be discovered and used to generate executable workflows. In this paper, we examine how Web ontologies can be used to write such template descriptions that will allow flexible matchmaking of services. We discuss the importance of expressing preferences in templates and provide a ranking algorithm based on DL inference services. We then present the HTN-DL formalism — an extension to the HTN planning formalism to generate compositions of Web Services based on these templates. Finally we present the experimental evaluation for the composition system we proposed.