Home
XSLT Processor
Website Editor
CGI XSLT Processor
The style and source
Global parameters
Stylesheets
Stylesheet elements
Functions
Files upload
Details
Characters model
Data types
Result tree fragments
Variables scope
Conflict resolution
The key function
The document function
Curly brackets in attributes
Extensions
Extension modules
XSL message handlers
XML tree class
The style and source parameters of XSLT engine

The main parameters of xsltp.pl Perl XSLT processor are style and source. You can pass them using GET or POST methods. The style parameter value is the name of the XSLT stylesheet to be executed and the source parameter value is the name of the XML document to be transformed. Typically, you will need to pass one of them. The only permitted extension of the style file is .xsl and the only permitted extension of the source file is .xml. These extensions will be added automatically if they are not provided. The program cannot process files with other extensions unless you load them explicitly by the stylesheet code. It is recommended to use not xml(xsl) extension for configuration files.

Security remark. The XSLT processor can read valid XML documents only. There is must be a stylesheet to display the document. Hence if you'll design the stylesheets carefully the above recommendation can be ignored. The source and style parameters are protected against null terminated strings and Perl IO control characters attacks.

If the style parameter is not set then the program reads the processing instruction
<?xml-stylesheet href="filename.style" type="text/xsl"?>
in the source file. If it is not present then xsltp.pl XSLT parser attempts to load the stylesheet with the same name as the source file and with .xsl extension. It is not an error if the source file is not passed. In this case your XSLT stylesheet must be prepared to start with the root node that has no children. Example,
/cgi-bin/xsltp.pl?style=doc/xsltp&source=doc/xsltp

The declaration of the style or source parameters in the stylesheet is not required, but if you need their values in the stylesheet code you can do this as
<xsl:param name="style" as="string"/>
<xsl:param name="source" as="string"/>

The style and source parameters must be file names on the local host, usually, relative paths. It does not mean that you cann't process XML data source from remote host. Here is the code you will use to do this.
<?xml version="1.0"?>
<!DOCTYPE my-news [<!ENTITY news SYSTEM "http://www.notdopscripts.com/xml/news.xml">]>
<xsl:stylesheet version="1.0">
<xsl:variable name="news">&news;</xsl:variable>
<xsl:template match="/">
<xsl:for-each select="$news">
....
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
This method works if news.xml has no XML declaration or has XML declaration with encoding type. External entities are not allowed in bytes characters model. Notice that the requirement for encoding in external entities is a corollary of XML physical structure definition. The XML parsers that don't follow the W3C Recommendation can read entities without encoding type.

How do I pass parameters to XSLT stylesheet?
How do I use one byte encodings?
Copyright © 2004 www.dopscripts.com