XSLT PI Parameters
Overview
XSLT supports the concept of passing parameters to a stylesheet when executing it. This is currently possible when using the XSLTProcessor in javascript. However when using an <?xml-stylesheet?> processing instruction (PI) there is currently no way to provide parameters.
To solve this two new PIs are proposed, <?xslt-param?> and <?xslt-param-namespace?>. Both PIs can contain "pseudo attributes" the same way that the xml-stylesheet PI does.
The following document passes the two parameters "color" and "size" to the stylesheet "style.xsl".
<?xslt-param name="color" value="blue"?> <?xslt-param name="size" select="2"?> <?xml-stylesheet type="text/xsl" href="style.xsl"?>
Processing instructions
The xslt-param PI supports 4 pseudo attributes:
- name
The local-name part of the parameter name. No syntax checking is done on the attribute, however if it is not a valid NCName it will never match any parameter in the stylesheet. - namespace
The namespace of the parameter name. - value
Contains the string value for the parameter. The value of the attribute is used as value for the parameter. The datatype will always be string. - select
An XPath expression for the parameter. The value of the attribute is parsed as an XPath expression. The result of evaluating the expression is used as value for the parameter.
If both value and select is present the value attribute is ignored. If neither value nor select is present the PI is ignored.
It is not an error to specify a parameter that does not exist in the stylesheet (or that is a variable in the stylesheet). The PI is simply ignored.
The select attribute
The following context is used to parse and evaluate the expression in the select attribute.
- The context node is the node used as initial current node used when executing the stylesheet.
- The context position is the position of the context node in the initial current node list used when executing the stylesheet.
- The context size is the size of the initial current node list used when executing the stylesheet.
- TODO: should we allow variable references in the expression? The current patch for mozilla does allow any toplevel variable and parameter in the stylesheet, but it might be a tough requirement on other XSLT engines.
- The function library is the standard XPath function library. TODO: should we allow any XSLT specific functions?
- The namespace declarations are determined by the xslt-param-namespace PIs, see below.
If the select attribute fails to parse or execute the PI is ignored (in particular, it does not fallback to the value attribute).