Pet*_*ter 8 xslt conditional conditional-statements
我有两个不同变量的AND和OR串联.我尝试了以下方法:
<xsl:if test="$countryCode = '104'
and
(transactionType != 'Allowance'
or
revenueCenter != '1100')">
Run Code Online (Sandbox Code Playgroud)
但这不起作用.是否可以进行条件测试,或者我必须将其拆分为:
<xsl:if test="$countryCode='104'>
Run Code Online (Sandbox Code Playgroud)
在第二个元素我做:
<xsl:if transactionType!='Allowance' or revenueCenter!='1100'>
Run Code Online (Sandbox Code Playgroud)
我在互联网上搜索但没有找到任何暗示.任何人都可以帮我找到解决方案.谢谢你,最诚挚的问候,彼得
Dim*_*hev 12
XPath表达式:
$countryCode='104'
and
(transactionType!='Allowance' or revenueCenter!='1100')
Run Code Online (Sandbox Code Playgroud)
在语法上是正确的.
我们不能说出语义,因为没有提供XML文档,也没有解释表达式必须选择的内容.
像往常一样,!=除非确实有必要,否则建议不要操作运算符 - 当其中一个参数是节点集(或XPath 2.0中的序列或节点集)时,它的使用与大多数人的预期相差甚远.
而不是!=更好地使用功能not():
$countryCode='104'
and
(not(transactionType='Allowance') or not(revenueCenter='1100'))
Run Code Online (Sandbox Code Playgroud)
这可以进一步重构为更短和等效:
$countryCode='104'
and
not(transactionType='Allowance' and revenueCenter='1100')
Run Code Online (Sandbox Code Playgroud)