with
语法
with $name = value;
描述
指定要传递到模板的参数。在对语句应用模板 apply-templates 或使用语句调用模板时,您可以使用此 call 语句。
或者,您可以通过包含等号 (=) 和值表达式来为参数指定值。如果未指定任何值,则参数的当前值将传递到模板。
属性
name |
为其传递值的变量或参数的名称。 |
value |
要传递到模板的参数值。 |
SLAX 示例
match configuration {
var $domain = domain-name;
apply-templates system/host-name {
with $message = "Invalid host-name";
with $domain;
}
}
match host-name {
param $message = "Error";
param $domain;
<hello> $message _ ":: " _ . _ " (" _ $domain _ ")";
}
XSLT 等效项
<xsl:template match="configuration">
<xsl:apply-templates select="system/host-name">
<xsl:with-param name="message" select="'Invalid host-name'"/>
<xsl:with-param name="domain" select="$domain"/>
</xsl:apply-templates>
</xsl:template>
<xsl:template match="host-name">
<xsl:param name="message" select="'Error'"/>
<xsl:param name="domain"/>
<hello>
<xsl:value-of select="concat($message, ':: ', ., ' (', $domain, ')')"/>
</hello>
</xsl:template>
使用示例
请参阅 示例:配置双路由引擎, 示例:防止导入完整路由表,以及 示例:自动配置逻辑接口和 IP 地址。
版本信息
在 SLAX 语言 1.0 版中引入的语句。