调用 XSL 模板时的可选参数 [英] Optional parameters when calling an XSL template
问题描述
有没有办法调用带有可选参数的 XSL 模板?
Is there way to call an XSL template with optional parameters?
例如:
<xsl:call-template name="test">
<xsl:with-param name="foo" select="'fooValue'" />
<xsl:with-param name="bar" select="'barValue'" />
</xsl:call-template>
以及由此产生的模板定义:
And the resulting template definition:
<xsl:template name="foo">
<xsl:param name="foo" select="$foo" />
<xsl:param name="bar" select="$bar" />
<xsl:param name="baz" select="$baz" />
...possibly more params...
</xsl:template>
这段代码会给我一个错误表达式错误:找不到变量‘baz’."是否可以省略baz"声明?
This code will gives me an error "Expression error: variable 'baz' not found." Is it possible to leave out the "baz" declaration?
谢谢,亨利
推荐答案
您使用的 xsl:param
语法错误.
You're using the xsl:param
syntax wrong.
改为这样做:
<xsl:template name="foo">
<xsl:param name="foo" />
<xsl:param name="bar" />
<xsl:param name="baz" select="DEFAULT_VALUE" />
...possibly more params...
</xsl:template>
Param 采用与 xsl:param
语句的名称相匹配的 xsl:with-param
传递的参数值.如果未提供,则采用 select
属性完整 XPath 的值.
Param takes the value of the parameter passed using the xsl:with-param
that matches the name of the xsl:param
statement. If none is provided it takes the value of the select
attribute full XPath.
可以在 W3School 关于 param 的条目 中找到更多详细信息.
More details can be found on W3School's entry on param.
这篇关于调用 XSL 模板时的可选参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!