<xsl:with-param> Element
Passes a parameter to a template.
<xsl:with-param name = QName select = Expression> </xsl:with-param>
Attributes
- name
- Required. 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
Number of occurrences | Unlimited |
Parent elements | xsl:apply-templates, xsl:call-template |
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 |
Remarks
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.
Example
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.
Note To test this example in Internet Explorer, you need to use a script. For more information, see Initiate XSLT in a Script.
XML File (app.xml)
<?xml version='1.0'?> <?xml-stylesheet type="text/xsl" href="showlocmsg.xsl" ?> <showmsg> <msg23/> </showmsg>
XML Resource File (resources/en.xml)
<?xml version='1.0'?> <messages> <message name="msg23">Error 23: The drive is full.</message> <message name="msg42">Error 42: The file is not found.</message> </messages>
XSLT File (showlocmsg.xsl)
<?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>
Output
This is the formatted output:
This is the processor output:
<?xml version="1.0" encoding="UTF-16"?>
See Also
<xsl:call-template> Element | <xsl:variable> Element | <xsl:param> Element | <xsl:template> Element