XSLT PI Parameters: Difference between revisions

From MozillaWiki
Jump to navigation Jump to search
(redirect)
 
(17 intermediate revisions by 7 users not shown)
Line 1: Line 1:
== Overview ==
#redirect [[mdc:XSLT:PI_Parameters]]
 
XSLT supports the concept of passing parameters to a stylesheet when executing it. This is currently possible when using the [http://www.mozilla.org/projects/xslt/js-interface.html 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'''<br>The local-name part of the parameter name. No syntax checking is done on the attribute, however if it is not a valid [http://www.w3.org/TR/REC-xml-names/#NT-NCName NCName] it will never match any parameter in the stylesheet.
* '''namespace'''<br>The namespace of the parameter name.
* '''value'''<br>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'''<br>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).

Latest revision as of 13:39, 3 January 2007