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
Passing parameters to XSLT stylesheet

Xsltp.pl XSLT engine uses HTTP protocol built in the processor for passing the parameters to XSLT stylesheets. The parameter passed to the XSLT processor must be declared in the global parameters section of the XSLT stylesheet.

The Perl XSLT processor treats the global parameters as constants. The values of global parameters are XPATH expressions. These expressions are not evaluated. Instead, the reference to the global parameter will be replaced by the expression at compile time. If the global parameter is a result tree fragment its value is converted to the literal string expression. In addition, for the top xsl:param elements, "as" and "max-size" attributes are optional.

The parameters you wish to pass to the XSLT stylesheet must have "as" attribute. Xsltp.pl XSLT parser supports the following values of "as" attribute:
int (or integer), unsigned-int (or unsignedInt), positiveInt (or positiveInteger),
number, string, expression, file,  set
The last two types are converted to the global variables. Parameters of type expression passed to the XSLT stylesheet must not contain a reference to variable or parameter, the document function and any extension function. Parameters of type set are result tree fragments of the form
<xsl:param name="options" as="set" max-sixe="100">
<value>1</value><value>2</value>...</xsl:param>
The following code determines is there 1 in the set
<xsl:if test="$options/value=1">...</xsl:if>

Here is an example of the HTML form which send the parameter of type set. It is assumed that stylesheet xml/checkbox.xsl defines the parameter named "options" either with default values as above or simply as
<xsl:param name="options" as="set"/>
<!-- HTML Form -->
<FORM action="/cgi-bin/xsltp.pl" method="POST">
<INPUT TYPE="hidden" NAME="style" VALUE="xml/checkbox">
value: <INPUT TYPE="checkbox" NAME="options" VALUE="1">
value: <INPUT TYPE="checkbox" NAME="options" VALUE="2">
value: <INPUT TYPE="checkbox" NAME="options" VALUE="3">
<INPUT TYPE="submit" NAME="test" VALUE="send">
</FORM>

The xsl:param element of string type can have the escape-chars attribute (v>=1.5). It has no effect on the default value.
<xsl:param name="str" as="string" max-size="20" escape-chars="'\n\r\\" select="''"/>

The max-size attribute for set type means max size of the string value of the result tree fragment plus max number of values (this is technically convenient). For file type the max-size attribute is meaningless. For all rest types the max-size attribute sets the maximum allowed size of the string passed as a parameter value to the XSLT processor. You can set the default value of the parameter with the select attribute. It is an error if the parameter with no default value is not passed to the XSLT stylesheet. Not declared parameters are discarded. Xsltp.pl program also reads HTTP COOKIE. If a parameter with name x has been passed with GET or POST methods x parameter in the http cookie list is ignored. Passing expressions to the processor as external parameters, check your XSLT stylesheet for possible infinite loop. The Perl XSLT parser has no algorithm of the infinite loop detection. In fact, any CGI program has this algorithm even if its author doesn't want it.

How can I save the result document on the local disk?
What can I do with parameters of file type?
How do I use the document function?
Copyright © 2004 www.dopscripts.com