Home > Articles > Programming > Java

  • Print
  • + Share This
This chapter is from the book

This chapter is from the book

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

   <TITLE>First XSLT Example</TITLE>
   <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>

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:

  1. Ensure that Internet Explorer 5.0 or later is installed.

  2. Create a new working directory.

  3. Save Listing 2.1 to this directory as invoice.xml.

  4. Save Listing 2.2 as invoice.xsl.

  5. Launch Windows Explorer and navigate to your working directory.

  6. Double-click invoice.xml.

  7. 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.

  • + Share This
  • 🔖 Save To Your Account