As mentioned earlier, in this tutorial, you will be recreating the structure of a pdf document, the Candidate Questionnaire (techauthor.pdf). You will do this using an existing XML document which will be formatted by an XSLT stylesheet you create. Be sure you have the pdf version of the document available for viewing either by opening it in Adobe Acrobat Reader™ or by printing it out. If you haven't already done so, click here to download a copy of it.
Since every XSLT stylesheet is an XML document, it needs to start off with an XML declaration.
1. To begin the stylesheet, type <?xsl:version="1.0"?> at the top of the page. This is the standard XML declaration.
2. Follow that with <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> to indicate the namespace for the stylesheet. A namespace is a label that distinguishes this stylesheet if it is combined with other stylesheets that may use some of the same node names.
3. At the bottom of the document, type </xsl:styleheet> which is the closing tag for the stylesheet.
Transforming XML using XSLTThe XSLT processor analyses the XML document and converts it into a hierarchal structure called a node tree. A node is simply an individual piece of the XML document structure. The XSLT processor then determines what to do with those nodes by referring to instructions contained in the XSLT stylesheet. The stylesheet uses templates that consist of two parts:
The processor starts by identifying the root node or the outermost node. It does this through the use of a root statement. |
4. Under the namespace declaration, type <xsl:template match="/">. This statement uses the forward slash to match to the root node of the document. The XSLT stylesheet will use this information to match itself to the root node in the XML document.
5. At the bottom of the document, type the closing tag for the root template </xsl:template> which should be placed just above the closing tag for the stylesheet.
6. Save the document as questionnaire.xsl in text file format. Be sure to save the document in the same folder as the XML document, using the extension .xsl which is the XSLT stylesheet extension.
At this point, your document should look like this:
<?xsl:version="1.0"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/ Transform" version="1.0"> <xsl:template match="/">
</xsl:template> </xsl:stylesheet> |
This completes the basic declarations for the XSLT stylesheet for the project. The next section, discusses adding HTML code to the stylesheet to create a framework for the XML content. Continue on to the section, Part II. Adding HTML Content.