다음을 통해 공유


xsl:param Element (Windows Embedded CE 6.0)

1/6/2010

Declares a named parameter for use within an xsl:stylesheet or xsl:template. Allows specification of a default value.

Syntax

<xsl:param
  name = QName
  select = expression>
</xsl:param>

Attributes

  • name
    [required] Specifies the name of the parameter.
  • select
    The value of the attribute is an expression, and the value of the variable is the object that results from evaluating the expression. When this attribute is specified, the content of <xsl:param> must be empty.

Element Information

Number of occurrences

Unlimited

Parent elements

xsl:stylesheet, xsl:template, xsl:transform

Child elements

xsl:apply-templates, xsl:attribute, xsl:call-template, xsl:choose, xsl:comment, xsl:copy, xsl:copy-of, xsl:element, xsl:for-each, xsl:if, xsl:processing-instruction, xsl:text, xsl:value-of, xsl:variable, output elements

Remarks

The value specified on the <xsl:param> element is a default value for binding. When the template or style sheet containing <xsl:param> is invoked, parameters are passed that are used in place of the default values.

The value of the parameter can be an object of any type that can be returned by an expression. The <xsl:param> element can specify the value of the variable in three alternative ways:

  • If the element has a select attribute, the value of the attribute must be an expression and the value of the parameter is the object that results from evaluating the expression. In this case, the content of the element must be empty.

  • If the element does not have a select attribute and has non-empty content such as one or more child nodes, the content specifies the value. The content is a template that is instantiated to give the value of the parameter. The value is a result-tree fragment equivalent to a node-set containing just a single root node having as children the sequence of nodes produced by instantiating the template. The base URI of the nodes in the result-tree fragment is the base URI of the element.
    An error occurs if a member of the sequence of nodes created by instantiating the template is an attribute node or a name space node, because a root node cannot have an attribute node or a name space node as a child.

  • If the content is empty and does not have a select attribute, the value of the parameter is an empty string. Thus

    <xsl:param name="x"/>
    

    is equivalent to

    <xsl:param name="x" select="''"/>
    

    Note

    When a parameter is used to select nodes by position, be careful not to do the following:

    <xsl:param name="n">2</xsl:param>
    ...
    <xsl:value-of select="item[$n]"/>
    

    This will output the value of the first item element, because the variable "n" will be bound to a result-tree fragment, not a number. Instead, do either

    <xsl:param name="n" select="2"/>
    ...
    <xsl:value-of select="item[$n]"/>
    

    or

    <xsl:param name="n">2</xsl:param>
    ...
    <xsl:value-of select="item[number($n)]"/>
    

    Note

    The following is a convenient way to specify the empty node-set as the default value of a parameter.

    <xsl:param name="x" select="/.."/>
    

Example

This example defines a named template for a "numbered-block" with an argument to control the format of the number.

<xsl:template name="numbered-block">
  <xsl:param name="format">1. </xsl:param>
  <fo:block>
    <xsl:number format="{$format}"/>
    <xsl:apply-templates/>
  </fo:block>
</xsl:template>

<xsl:template match="ol//ol/li">
  <xsl:call-template name="numbered-block">
    <xsl:with-param name="format">a. </xsl:with-param>
  </xsl:call-template>
</xsl:template>

See Also

Reference

XSLT Elements
xsl:variable Element
xsl:call-template Element