如何在 XSLT 中更改或重新分配变量? [英] How to change or reassign a variable in XSLT?
问题描述
如何将值重新分配给先前分配的变量?我需要它像这样工作:
How can I reassign a value to a variable previously assigned? I need it to works like this:
<xsl:variable name="variable2" select="'N'" />
....
<xsl:when test="@tip = '2' and $variable2 != 'Y'">
<xsl:variable name="variable2" select="'Y'" />
</xsl:when>
推荐答案
XSLT 中的变量只能赋值一次.这是由设计完成的.请参阅为什么使用函数式语言?了解总体动机.
Variables in XSLT may only be assigned a value once. This is done by design. See Why Functional languages? for an appreciation of the motivation in general.
与其重新分配变量,不如直接针对输入文档编写条件,或使用不同的局部参数递归调用函数(或命名模板).
Rather than reassign a variable, write conditionals against the input document directly, or call a function (or named template) recursively with varying local parameters.
您需要做的任何事情都可以通过不需要重新分配变量的方法来完成.要获得更具体的答案,请提供更具体的问题.
Anything you need to do can be done with an approach that does not require reassignment of variables. To receive a more specific answer, provide a more specific question.
另见:
这篇关于如何在 XSLT 中更改或重新分配变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!