web analytics

xsl:param and xsl:with-param

Options

codeling 1595 - 6639
@2016-12-28 19:45:06

The <xsl:param> element is used to declare a local or global parameter. The parameter is global if it's declared as a top-level element, and local if it's declared within a template.

@2016-12-28 19:59:41

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:

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

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

c. 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="''"/>

@2016-12-28 20:05:39

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)]"/>

@2016-12-28 20:07:59

The <xsl:with-param> element defines the value of a parameter to be passed into a template.

The value of the name attribute of <xsl:with-param> must match a name in an <xsl:param> element (the <xsl:with-param> element is ignored if there is no match).

The <xsl:with-param> element is allowed within <xsl:apply-templates> and <xsl:call-template>.

Comments

You must Sign In to comment on this topic.


© 2024 Digcode.com