XSLT PI Parameters: Difference between revisions

From MozillaWiki
Jump to navigation Jump to search
Line 13: Line 13:
== Processing instructions ==
== Processing instructions ==


The xslt-param PI supports 4 pseudo attributes:
The attributes in the '''xslt-param''' and '''xslt-param-namespace''' PIs are parsed using the rules defined in [http://www.w3.org/TR/xml-stylesheet/ xml-stylesheet]. If any unrecognized attributes must be ignored. Parsing of any attribute must not fail due to the presence of an unrecognized attribute as long as that attribute follows the syntax in xml-stylesheet.
 
Both the '''xslt-param''' and the '''xslt-param-namespace''' PIs must appear in the prolog of the document, i.e. before the first element tag. All PIs in the prolog must be honored, both ones occuring before and onces occuring after any xml-stylesheet PIs.
 
=== xslt-param ===
 
The '''xslt-param''' PI supports 4 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.
* '''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.
* '''namespace'''<br>The namespace of the parameter name. No syntax checking is done on the attribute.
* '''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''.
* '''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.
* '''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 the '''name''' attribute is missing or empty the PI is ignored.
if the '''namespace''' attribute is missing or empty the null namespace is used.


If both '''value''' and '''select''' is present the '''value''' attribute is ignored. If neither '''value''' nor '''select''' is present the PI is ignored.
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.
It is not an error to specify a parameter name that does not exist in the stylesheet (or that is a variable in the stylesheet). The PI is simply ignored.


=== The select attribute ===
==== The select attribute context ====
The following context is used to parse and evaluate the expression in the '''select''' attribute.
The following context is used to parse and evaluate the expression in the '''select''' attribute.


Line 35: Line 45:


If the '''select''' attribute fails to parse or execute the PI is ignored (in particular, it does not fallback to the value attribute).
If the '''select''' attribute fails to parse or execute the PI is ignored (in particular, it does not fallback to the value attribute).
=== xslt-param-namespace ===
The '''xslt-param-namespace''' uses two attributes:
* '''prefix'''<br>The prefix that is mapped.
* '''namespace'''<br>The namespace the prefix maps to.
An '''xslt-param-namespace''' PI affects the expression in the '''select''' attribute for all '''xslt-param'''s following the PI. This applies even if there are other nodes such as comments or other PIs between the '''xslt-param-namespace''' and '''xslt-param''' PIs.
It is not an error for multiple PIs to use the same prefix, every new PI just changes what namespace the prefix maps to.
If either '''prefix''' or '''namespace''' is missing or empty the PI is ignored. If '''prefix''' is not a valid NCName it is ignored.

Revision as of 08:35, 24 March 2006

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 attributes in the xslt-param and xslt-param-namespace PIs are parsed using the rules defined in xml-stylesheet. If any unrecognized attributes must be ignored. Parsing of any attribute must not fail due to the presence of an unrecognized attribute as long as that attribute follows the syntax in xml-stylesheet.

Both the xslt-param and the xslt-param-namespace PIs must appear in the prolog of the document, i.e. before the first element tag. All PIs in the prolog must be honored, both ones occuring before and onces occuring after any xml-stylesheet PIs.

xslt-param

The xslt-param PI supports 4 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. No syntax checking is done on the attribute.
  • 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 the name attribute is missing or empty the PI is ignored.

if the namespace attribute is missing or empty the null namespace is used.

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 name that does not exist in the stylesheet (or that is a variable in the stylesheet). The PI is simply ignored.

The select attribute context

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).

xslt-param-namespace

The xslt-param-namespace uses two attributes:

  • prefix
    The prefix that is mapped.
  • namespace
    The namespace the prefix maps to.

An xslt-param-namespace PI affects the expression in the select attribute for all xslt-params following the PI. This applies even if there are other nodes such as comments or other PIs between the xslt-param-namespace and xslt-param PIs.

It is not an error for multiple PIs to use the same prefix, every new PI just changes what namespace the prefix maps to.

If either prefix or namespace is missing or empty the PI is ignored. If prefix is not a valid NCName it is ignored.