我正在尝试根据XSLT中的一些javascript布尔变量更新我的XML数据,我不确定使用它的最佳方法是什么。我尝试下面的代码,但它似乎不起作用。你能帮帮我吗?
使用Javascript:
<msxsl:script language="JScript" implements-prefix="usr">
<![CDATA[
var FDAttempt = false;
function setFDAttemptTrue()
{
FDAttempt = true;
}
function getFDAttempt()
{
return FDAttempt;
}
]]>
</msxsl:script>
在其中一个模板中设置变量
<xsl:template name="FDTemplate">
<xsl:if test ="usr:setFDAttemptTrue()" />
<Tran>
<TranName>FDAttempt</TranName>
<Result>Forced</Result>
</Tran>
</xsl:template>
检查布尔值:这是检查的正确方法吗
<xsl:when test ="Content/Journal">
<xsl:variable name="x" select ="Content/*[1]" />
<xsl:variable name="ForcedAttempt" select="usr:getFDAttempt()" />
<xsl:if test ="$x/Name='Complete' and $x/Details='Error' and $ForcedAttempt='false'">
<OutPut>
<Name>SDM</Name>
<Location>Transport</Result>
</OutPut>
</xsl:if>
</xsl:when>
答案 0 :(得分:0)
Programming XSLT code that tries to get away with side-effects is a constant battle against the optimizer. You're quite likely to find that an instruction like
<xsl:if test ="usr:setFDAttemptTrue()" />
gets optimized away because it produces an empty result whether or not the test condition is true.
And your example doesn't really convince me that using extension functions and side-effects is needed to solve the problem you are tackling. (I would be more likely to be convinced if you described the problem.) As far as I can see, what you are doing could be achieved with simple xsl:param
/xsl:with-param
mechanisms.