This tutorial discusses how to use an XSLT stylesheet to transform an existing XML document into another format, such as HTML or XHTML. To complete this tutorial, you will need a good knowledge of HTML and a fair understanding of XML.
To better understand the transformation process, we will do an exercise that involves recreating the structure of a pdf document (Figure 1 below). We will accomplish this by using an XML version of the document's contents and structure it using XSLT. If you wish to download the pdf file for viewing, click here.
![]() |
||
Figure 1. Page 1 of the PDF file |
The following section is a brief overview of XSLT. If you are already familiar with XSLT then you can skip over this section and go to the tutorial.
XSLT (EXtensible Stylesheet Language Transformations) is a stylesheet language, which is created from XML. XSLT is primarily used to apply structure formatting to an XML document. It accomplishes this by:
Since XSLT is created from XML it follows the same structural guidelines. For example, similar to XML, XSLT must be written in only lowercase letters (A more complete set guidelines follows later in this tutorial).
Both XSLT and XML are text-based markup languages so they may be created or edited using a simple text editor, like Notepad.
Figure 2. From XML to HTML
Similar to CSS (Cascading Style Sheets), XSLT is used to provide structure to an XML document. XSLT was designed to work primarily with XML while CSS was designed to work primarily with HTML or XHTML. Both CSS and XSLT allow:
However unlike CSS, XSLT has more functionality. For example, it has the ability to sort or filter the elements of an XML document. XSLT is able to format the document's structure. CSS can only format the document's content. However, the soon-to-be released CSS2 should be able to format both.
The next section discusses what you will need to transform XML into XSLT. On to Getting Started.