简体   繁体   English

xsl:param和xsl:variable之间的区别

[英]difference between xsl:param and xsl:variable

i am considering either one to use when defining an xsl:template name = myTemplate that will be called in another xsl file. 我正在考虑在定义xsl时使用其中一个:模板名称= myTemplate将在另一个xsl文件中调用。

legacy code seems to use 'xsl:variable' when being used in xsl:template match="legacyTemplate" 遗留代码似乎在xsl中使用'xsl:variable':template match =“legacyTemplate”

so what's the difference between xsl:param and xsl:variable when using it in xsl:template name=myTemplate? 那么xsl:param和xsl:variable在xsl中使用它时有什么区别:template name = myTemplate?

The difference is that the value of an xsl:param could be set outside the context in which it is declared. 不同之处在于xsl:param的值可以在声明它的上下文之外设置。 For example, see: 例如,请参阅:

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

then you know that $v will always give you the string 'y' . 然后你知道$v总会给你字符串'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: 但是对于$p ,字符串'x'只是默认值:如果使用xsl:apply-templatesxsl:call-template ,则会看到不同的值,其中包含如下指令:
<xsl:with-param name="p" select="'not x'" />

<xsl:param> may also be used outside xsl:template , at the top level in the stylesheet. <xsl:param>也可以在xsl:template外部使用,位于样式表的顶层。 The value of such a parameter may be set when the XSLT processor is called. 可以在调用XSLT处理器时设置此参数的值。 How this is done depends on the processor and whether you call it from the command line or by program. 如何完成取决于处理器以及是从命令行还是通过程序调用它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM