xsl:param 和 xsl:variable 的区别 [英] difference between xsl:param and xsl:variable

查看:24
本文介绍了xsl:param 和 xsl:variable 的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在考虑在定义将在另一个 xsl 文件中调用的 xsl:template name = myTemplate 时使用其中任何一个.

i am considering either one to use when defining an xsl:template name = myTemplate that will be called in another xsl file.

遗留代码在 xsl:template match="legacyTemplate" 中使用时似乎使用了 'xsl:variable'

legacy code seems to use 'xsl:variable' when being used in xsl:template match="legacyTemplate"

那么在 xsl:template name=myTemplate 中使用 xsl:param 和 xsl:variable 有什么区别?

so what's the difference between xsl:param and xsl:variable when using it in xsl:template name=myTemplate?

推荐答案

区别在于 xsl:param 的值可以是在声明它的上下文之外设置.例如,见:

The difference is that the value of an xsl:param could be set outside the context in which it is declared. For example, see:

<xsl:template ...>
   <xsl:param name="p" select="'x'" />
   <xsl:variable name="v" select="'y'" />
...

那么你知道$v 总是会给你字符串'y'.但是对于 $p 字符串 'x' 只是一个默认值:如果使用以下任一方式调用模板,您将看到不同的值xsl:apply-templatesxsl:call-template 包含指令例如:

then you know that $v will always give you the string 'y'. But for $p the string 'x' is only a default: you will see a different value if the template is invoked with either xsl:apply-templates or xsl:call-template which contains an instruction such as:
<xsl:with-param name="p" select="'not x'" />

也可以在 xsl:template 之外使用,在样式表.可以在以下情况下设置此类参数的值XSLT 处理器被调用.这是如何完成的取决于处理器以及您是从命令行还是通过程序调用它.

<xsl:param> may also be used outside xsl:template, at the top level in the stylesheet. The value of such a parameter may be set when the XSLT processor is called. How this is done depends on the processor and whether you call it from the command line or by program.

这篇关于xsl:param 和 xsl:variable 的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆