XML is rapidly emerging as a dominant standard for representing and exchanging information. The ability to transform and present data in XML is crucial and XSLT (Extensible stylesheet transformations) is a relatively recent programming language, specially designed to support this activity. Despite its utility, however, XSLT is widely considered a difficult language to learn. In this paper, we present a novel system called XSLTGen, an automatic XSLT Generator. This system automatically generates an XSLT program, given a source XML document and a desired output HTML or XML document. It allows users to become familiar with and learn XSLT programs, based solely on their knowledge of XML or HTML. Our method for automatically generating XSLT transformations is based on the use of semantic mappings between the input and output documents. We show how such mappings can be first discovered and then employed to create XSLT programs. The results of our experiments show that XSLTGen works well with a number of different varieties of XML and HTML documents.