Xml 如何对照XSLT1.0中的一组值检查变量?
我有以下条件要测试Xml 如何对照XSLT1.0中的一组值检查变量?,xml,xslt,xslt-1.0,Xml,Xslt,Xslt 1.0,我有以下条件要测试 <xsl:if test=" $Occupation='5' or $Occupation='7' or $Occupation='N' or $Occupation='M' or $Occupation='J' or $Occupation='V' or $Occupation='W'
<xsl:if test=" $Occupation='5'
or $Occupation='7'
or $Occupation='N'
or $Occupation='M'
or $Occupation='J'
or $Occupation='V'
or $Occupation='W'">
<xsl:value-of select="'Accounts'"/>
</xsl:if>
有这样的检查方法吗
<xsl:if test="$occupation contains('5','7','N','W','J','M')">
您可以使用:
<xsl:if test="contains('57NMJ', $Occupation)">
假设列表中的所有内容都是单个字符:
<xsl:if test="string-length($occupation) = 1 and contains('57NWJM', $occupation)">
<xsl:value-of select="'Accounts'"/>
</xsl:if>
如果条目长度超过一个字符,则可以使用分隔字符。当然,此字符不能出现在列表中的任何值中。使用空格作为分隔符,情况可能如下所示:
<xsl:if test="not(contains($occupation, ' ')) and contains(' foo bar baz ', concat(' ', $occupation, ' '))">
<xsl:value-of select="'Accounts'"/>
</xsl:if>
请确保不要忘记
foo
之前和baz
之后的填充空格,否则可能会出现问题
<xsl:if test="contains('57NWJM',$Occupation)">
XSLT 2.0
在XSLT 2.0中,您可以更清晰地执行此操作:
$occupation = ('5','7','N','M','J','V','W')
XSLT1.0
对于像您这样的单字符值情况,XPath 1.0表达式
translate($occupation,'7NMJVW','555555')='5'
当$occulation
为5
、7
、N
、M
、J
、V
或W
时,将返回true
对于单字符或多字符值的情况,请参见或,其采用了一种常用的技术:
translate($occupation,'7NMJVW','555555')='5'
contains(concat(" ", normalize-space(@class), " "), " target ")]