Important:
This is retired content. This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies. This content may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist.
A version of this page is also available for
4/8/2010

Passes a parameter to a template.

Syntax

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

Attributes

name

[required] Specifies the name of the parameter.

select

An expression to be matched against the current context. There is no default value. An empty string is generated if there is no content.

Element Information

Remarks

The required nameattribute specifies the name of the parameter (the variable, the value of whose binding is to be replaced). The <xsl:with-param> element is allowed within both <xsl:call-template> and <xsl:apply-templates>. The value of the parameter is specified in the same way as for <xsl:variable> and <xsl:param>. The current node and current node-list used for computing the value specified by the <xsl:with-param> element is the same as that used for the <xsl:apply-templates> or <xsl:call-template> element within which it occurs. It is not an error to pass a parameter xto a template that does not have an <xsl:param> element for x; the parameter is simply ignored.

Example

Suppose messages for a language L are stored in an XML file resources/L.xml in the following form.

Copy Code
<messages>
  <message name="problem">A problem was
detected.</message>
  <message name="error">An error was
detected.</message>
</messages>

A style sheet can use the following approach to localize messages.

Copy Code
<xsl:param name="lang" select="en"/>
<xsl:variable name="messages"
  select="document(concat('resources/', $lang,
'.xml'))/messages"/>

<xsl:template name="localized-message">
  <xsl:param name="name"/>
  <xsl:message>
	<xsl:value-of select="$messages/message[@name=$name]"/>
  </xsl:message>
</xsl:template>

<xsl:template name="problem">
  <xsl:call-template name="localized-message"/>
	<xsl:with-param
name="name">problem</xsl:with-param>
  </xsl:call-template>
</xsl:template>

See Also