8.3. Stylesheet Processors
An XSLT processor is a piece of software that reads an XSLT stylesheet, reads an input XML document, and builds an output document by applying the instructions in the stylesheet to the information in the input document. An XSLT processor can be built into a web browser, just as MSXML is in Internet Explorer 6. It can be built into a web or application server, as in the Apache XML Project's Cocoon (http://xml.apache.org/cocoon). Or it can be a standalone program run from the command like Michael Kay's SAXON (http://saxon.sourceforge.net) or the Apache XML Project's Xalan (http://xml.apache.org/xalan-j/ ).
8.3.1. Command-Line Processors
The exact details of how to install, configure, and run the XSLT processor naturally vary from processor to processor. Generally, you have to install the processor in your path, or add its jar file to your class path if it's written in Java. Then you pass in the names of the input file, stylesheet file, and output file on the command line. For example, using Xalan, Example 8-3 is created in this fashion:
% java org.apache.xalan.xslt.Process -IN people.xml -XSL minimal.xsl -OUT 8-3.txt ========= Parsing file:D:/books/xian/examples/08/minimal.xsl ========== Parse of file:D:/books/xian/examples/08/minimal.xsl took 771 milliseconds ========= Parsing people.xml ========== Parse of people.xml took 90 milliseconds ============================= Transforming... transform took 20 milliseconds XSLProcessor: done
For exact details, you'll need to consult the documentation that comes with your XSLT processor.
8.3.2. The xml-stylesheet Processing Instruction
XML documents that will be served directly to web browsers can have an xml-stylesheet processing instruction in their prolog telling the browser where to find the associated stylesheet for the document, as discussed in the last chapter. If this stylesheet is an XSLT stylesheet, then the type pseudoattribute should have the value application/xml. For example, this xml-stylesheet processing instruction says that browsers should apply the stylesheet found at the absolute URL http://www.oreilly.com/styles/people.xsl. Relative URLs can also be used.
<?xml version="1.0"?> <?xml-stylesheet type="application/xml" outsideurl=/styles/people.xsl"?> <people> ...
TIP: Microsoft Internet Explorer uses type="text/xsl" for XSLT stylesheets. However, the text/xsl MIME media type has not been and will not be registered with the IANA. It is a figment of Microsoft's imagination. In the future, application/xslt+xml will probably be registered to identify XSLT stylesheets specifically.
Copyright © 2002 O'Reilly & Associates. All rights reserved.