Perl CGI XSLT Processor
Xsltp.pl is a pure Perl XSLT processor. It requires XML::Parser and CGI packages and version of Perl 5.6.1 or higher. It supports XSLT 1.0 and XPath 1.0 W3C Recommendation. The built-in HTTP protocol makes the processor to be especially suited for Web development. Designed on "top" of Perl rather than "inside" of Perl it is ready for use CGI program. Open architecture of the processor allows developers to extend functionality of the XSLT processor by just coping the extension module, written in Perl, in the desired place and instructing the program that it must load it when the module is required by the XSLT stylesheet.
We provide three different methods for integration of the XSLT processor with Perl modules. The simplest one is xsl:message handlers. The XSL message handler is an independent package that defines the function message_handler. The input for the function is generated by the XSLT processor through processing the xsl:message element body and passing the result to the message_handler. The handler can open a file stream and print the result to it as XML/HTML document or convert the result to string and send the query to SQL server.
Extension instructions and functions are two other approaches. They are implemented by extension modules. The modules are loaded in the namespace of XSLT Perl package and XPath::Expression package. Possible names conflict should be resolved with the element name prefixes. The processor loads the extension when it finds the attribute xmlns:prefix="#module-name" of the xsl:stylesheet element.
To reduce number of problems with encodings we also support bytes characters model. The reason for that is that it is difficult to detect the encoding of the external source of data. The bytes model is more limited than Unicode model. In particular, the use of character references and external entities is not permitted. Advantages of the bytes model is that the processor returns the data in the same format as it receives them from external source like SQL server or file. Recall Perl uses UTF-8 encoding as a default and converts to it every string when it is "needed". Latin writers should not think about it at all.
The processor is also suitable for external parameter dependent display of XML files on a server-side. In addition, it has built-in extensions file upload feature, time functions, dynamic importing of sylesheets and method for HTTP headers printing.
The XSLT processor reads the parameters passed through HTTP GET or POST methods. The result documents can be saved to the local disk or(and) printed to STDOUT. A special element "xml-document" was introduced for the XSLT stylesheet can control the processor output. It is possible to add the code implementing a different method of parameters passing. The stylesheet must have the section of the global parameters declaration in this case either. Any parameter passed to the XSLT processor must have a type supported by it.
It seems that we get maximum possible performance for pure Perl solution. The execution time of the script depends linearly on the size of input and the size of output and varies with complexity of stylesheets. Gain from optimization of the compilation time can not be essential. It is due to the fact that 50% of the compilation time is spent by XML::Parser. Since version 1.5 the XSLT processor is compatible with mod_perl.