Outputting the Results
So, how do you get output from the XSL processor? The answer depends on how you invoke the processor. For our purposes, let's assume that this is a static style sheet stored in a file called invoice.xsl. Now, you can attach the style to the XML source document in one of two ways. The easiest is to include an <?xml-stylesheet> directive in the source document. If you leaf back to Listing 2.1, you'll notice the following statement at the top of the listing:
<?xml-stylesheet type="text/xsl" href="invoice.xsl"?>
When the XML parser sees this line, invoice.xsl is loaded and applied to the source document. The resulting output is shown in Listing 2.4.
Listing 2.4 Output from the XSLT Processor
<HTML> <HEAD> <TITLE>First XSLT Example</TITLE> </HEAD> <BODY> <P><B>Company: </B>ACME Programming Company</P> <P><B>Contact: </B>Kris Butler</P> <P><B>Services Rendered: </B>XML Training </P> <P><B>Total Due: </B>$1000</P> </BODY> </HTML>
If you happen to be working with an XML processor on the command line, the parser will most likely output the code in Listing 2.4 to the screen.
If you have a copy of Internet Explorer 5.x or later, however, you can easily test this example by launching invoice.xml in the browser. The browser, which includes an XML parser, will load the document, validate it, and then apply the style sheet. The steps for doing this are as follows:
Ensure that Internet Explorer 5.0 or later is installed.
Create a new working directory.
Save Listing 2.1 to this directory as invoice.xml.
Save Listing 2.2 as invoice.xsl.
Launch Windows Explorer and navigate to your working directory.
Double-click invoice.xml.
View the results.
When XSLT processor outputs the code in Listing 2.4, the browser will see the HTML code and render it as an HTML document. Therefore, instead of seeing Listing 2.4, you'll see the results of rendering the HTML. The results are shown in Figure 2.3.
Figure 2.3 The results of the transformation from the XSLT processor. The output is HTML, which is displayed in Internet Explorer.