8.3 Stylesheet Processors

     

An XSLT processor is a piece of software that reads an XSLT stylesheet, reads an 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 line like Michael Kay's SAXON (http://saxon. sourceforge .net) or the Apache XML Project's Xalan (http://xml.apache.org/xalan-j).

Internet Explorer 5.0 and 5.5 partially support a very old and out-of-date working draft of XSLT, as well as various Microsoft extensions to this old working draft. They do not support XSLT 1.0, and indeed no XSLT stylesheets in this book work in IE5. Stylesheets that are meant for Microsoft XSLT can be identified by their use of the http://www.w3.org/TR/WD-xsl namespace. IE6 supports both http://www.w3.org/1999/XSL/Transform and http://www.w3.org/TR/WD-xsl . Good XSLT developers don't use http://www.w3.org/TR/WD-xsl and don't associate with developers who do.


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 pseudo-attribute 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  "  href="http://www.oreilly.com/styles/people.xsl"?>  <people> ...  

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 be registered to identify XSLT stylesheets specifically .




XML in a Nutshell
XML in a Nutshell, Third Edition
ISBN: 0596007647
EAN: 2147483647
Year: 2003
Pages: 232

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net