<xsl:with-param> Element
Passes a parameter to a template.
<xsl:with-param name = QName select = Expression </xsl:with-param>
- name
-
Required. The Qualified Names of the parameter.
- select
-
An Expressions to be matched against the current context. There is no default value. An empty string is generated if there is no content.
| Number of occurrences | Unlimited |
| Parent elements | |
| 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 |
The name attribute is required. It specifies the name of the parameter. The parameter is 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.
If you pass a parameter x to a template that does not have an <xsl:param> element for x, this is not an error; the parameter is simply ignored.
A style sheet can use the following approach to call localized message strings.
The messages for a language somelanguage are stored in an XML file, resources/languageabbreviation.xml, in the form shown in the sample XML file below.
<?xml version='1.0'?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <!-- These 2 elements effectively assign $messages = resources/en.xml/<messages>, then $messages is used in the "localized-message" template. --> <xsl:param name="lang">en</xsl:param> <xsl:variable name="messages" select="document(concat('resources/', $lang, '.xml'))/messages"/> <xsl:template name="msg23" match="msg23"> <xsl:call-template name="localized-message"> <xsl:with-param name="msgcode">msg23</xsl:with-param> </xsl:call-template> </xsl:template> <xsl:template name="localized-message"> <xsl:param name="msgcode"/> <!-- Show message string. --> <xsl:message terminate="yes"> <xsl:value-of select="$messages/message[@name=$msgcode]"/> </xsl:message> </xsl:template> </xsl:stylesheet>