问题所在
示例代码:
<xsl:variable name="isMatch" select="'false'">
<xsl:for-each select="$information/Person>
<xsl:if test="@Name='ZhangSan'">
<xsl:variable name="isMatch" select="'true'">
</xsl:if>
</xsl:for-each>
最近在写xsl:template时,想使用一个全局变量作为标识,像java那样做for循环去判断,当满足条件时改变全局变量的值。
结果不论如何就是不生效,后续无法根据这个标识变量进入不同的业务逻辑。
查资料发现,xslt中新建xsl:variable后,变量的值是不会改变的,根本不存在全局变量这种说法。
可行办法
既然变量的值设置后无法改变,那还是在变量上做手脚,才能达到将变量作为标识使用的目的。
<xsl:variable name="isMatch">
<xsl:for-each select="$information/Person>
<xsl:if test="@Name='ZhangSan'">
<xsl:value-of select="'true'">
</xsl:if>
</xsl:for-each>
</xsl:variable>