xsl:param

Declares a parameter for a stylesheet or template, and specifies a default value for the parameter.

Format

<xsl:param name="parameter_name"  
  [select = "expression1"] 
  [expr = "expression2"]> 
  [template_body] 
</xsl:param> 

Description

The xsl:param instruction declares a parameter and specifies its default value. Another value can be passed to this parameter when the template or stylesheet that contains this xsl:param instruction is invoked.

The xsl:param element must be a child of either an xsl:stylesheet or xsl:template element.

The name attribute is required, and it must be a string. The value of the name attribute is a qualified name.

The value that you bind to a parameter can be an object of any of the types that are returned by expressions. You can specify the value of the parameter in several ways:

The XSLT processor interprets the value of the expr attribute as an attribute value template and uses the resulting string as if it were the value of the select attribute. If you specify the expr attribute, the XSLT processor ignores any contents of xsl:param.

The use of the expr attribute is an extension to the XSLT specification.

For any use of the xsl:param element, there is a region of the stylesheet tree within which the binding is visible. This region includes the siblings that follow the xsl:param instruction together with their descendants. Within this region, any binding of the parameter that was visible on the xsl:param element itself is hidden. Thus, only the innermost binding of a parameter is visible. The set of parameter bindings in scope for an expression consists of those bindings that are visible at the point in the stylesheet where the expression occurs.

The xsl:param instruction can be a top-level element. If it is, it declares a global parameter that is visible to the entire stylesheet. When the XSLT processor evaluates the select or expr attribute in a top-level xsl:param instruction, the current node is the root node of the document.

Passing parameters to templates

Use the xsl:with-param instruction to pass a value for a parameter to a template.

 
Free Stylus Studio XML Training: