web analytics
xsl:param and xsl:with-param Options
codeling
Posted: Wednesday, December 28, 2016 7:45:06 PM

Rank:Advanced Member
Groups: Member
Joined: 12/11/2015
Posts: 784
Points: 3288

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.

Sponsor
Posted: Wednesday, December 28, 2016 7:45:06 PM
codeling
Posted: Wednesday, December 28, 2016 7:59:41 PM

Rank:Advanced Member
Groups: Member
Joined: 12/11/2015
Posts: 784
Points: 3288

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

codeling
Posted: Wednesday, December 28, 2016 8:05:39 PM

Rank:Advanced Member
Groups: Member
Joined: 12/11/2015
Posts: 784
Points: 3288

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

codeling
Posted: Wednesday, December 28, 2016 8:07:59 PM

Rank:Advanced Member
Groups: Member
Joined: 12/11/2015
Posts: 784
Points: 3288

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

Users browsing this topic
Guest

Forum Jump
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.


© 2017 Digcode.com. All rights reserved.