本文介绍了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 beset 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 eitherxsl:apply-templates or xsl:call-template which contains an instructionsuch 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 inthe stylesheet. The value of such a parameter may be set when theXSLT processor is called. How this is done depends on the processorand whether you call it from the command line or by program.

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

07-29 13:25
查看更多