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:

  • Specify the select attribute. The value of the select attribute must be an expression. The XSLT processor evaluates the expression, and the result is the default value of the parameter. If you specify the select attribute, the XSLT processor ignores any value you might specify for the expr attribute, and also ignores any contents of xsl:param.
  • Specify the expr attribute. The expr attribute allows computation of an expression. For example:
    <xsl:param name="query" expr="//VEHICLE[MAKE='{$make}']"/>
                           
    
                        

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.

  • Specify template_body. The XSLT processor instantiates this template to obtain the default value of the parameter.
  • If you do not specify the select attribute, the expr attribute, or template_body, the default value of the parameter is an empty string.

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.

XQuery Functions - User Defined Functions in XQuery

Dr. Michael Kay's tutorial entitled: 'Defining your own Functions in XQuery' explains how to write powerful User Defined Functions in XQuery.

XML Schema Mapping

Stylus Studio includes a visual XML Schema-to-XML Schema mapping tool that allows you to easily implement sophisticated XML data mappings involving multiple data sources and customized data processing using either XSLT or XQuery code.

XML Schema Editor

Stylus Studio's XML Schema Editor lets you easily develop advanced data models expressed in W3C XML Schema. Its synchronized split-pane interface shows both a visual XML Schema Diagram and the underlying code, and you can edit in either one.

DataDirect XML Converters

DataDirect XML Converters are high-performance Java components which provide bi-directional, programmatic access to virtually any data source as XML.

Stylus Most Wanted

 
Free Stylus Studio XML Training:
W3C Member