0 out of 2 rated this helpful - Rate this topic

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

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'?>
<?xml-stylesheet type="text/xsl" href="showlocmsg.xsl" ?>
<showmsg>
   <msg23/>
</showmsg>

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

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

This is the formatted output:

Sample output

This is the processor output:

<?xml version="1.0" encoding="UTF-16"?>

Did you find this helpful?
(1500 characters remaining)
© 2013 Microsoft. All rights reserved.