我有两个不同变量的 AND 和 OR 串联。我尝试了以下方法:
<xsl:if test="$countryCode = '104'
and
(transactionType != 'Allowance'
or
revenueCenter != '1100')">
但这不起作用。是否可以进行条件测试,或者我是否必须像这样拆分它:
<xsl:if test="$countryCode='104'>
在第二个元素中,我这样做:
<xsl:if transactionType!='Allowance' or revenueCenter!='1100'>
我在互联网上搜索,但找不到任何关于此的提示。任何人都可以帮我找到解决方案。
感谢你并致以真诚的问候,
彼得
最佳答案
XPath 表达式 :
$countryCode='104'
and
(transactionType!='Allowance' or revenueCenter!='1100')
语法正确 .
我们不能谈论语义,因为没有提供 XML 文档,也没有解释表达式必须选择什么。
像往常一样,建议不要使用
!=
运算符(operator),除非真的有必要 -- 当参数之一是节点集(或 XPath 2.0 中的序列或节点集)时,它的使用与大多数人的期望相差甚远。而不是
!=
更好地使用功能not()
: $countryCode='104'
and
(not(transactionType='Allowance') or not(revenueCenter='1100'))
这可以进一步重构为更短的和等效的:
$countryCode='104'
and
not(transactionType='Allowance' and revenueCenter='1100')
关于xslt - 条件 AND OR 两个不同的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5458959/