如何使用dataweave检查两个条件

时间:2016-04-21 17:17:00

标签: mule dataweave

<root>
    <risk>
        <Category>02</Category>
        <NCD>
            <CoverCode>B05</CoverCode>
            <CI>
                <CD>3</CD>
            </CI>
        </NCD>
    </risk>
</root>

我需要检查2个条件以从上面获得所需的有效载荷。我正在使用如下的转换来检查2个条件。我希望只有当Category为02且CoverCode为B05时才能得到CD的值。

%dw 1.0
%output application/xml skipNullOn="everywhere"
%namespace soapenv http://schemas.xmlsoap.org/soap/envelope/
---
{
    soapenv#Envelope: {
        soapenv#Body: {

            component:{
                coverageClassCode:payload.root.risk.NCD.CI.CD when payload.root.risk.Category == '02' && payload.root.risk.NCD.CoverCode == 'B05' otherwise "" ,
                blockedDr:"N"
            }
        }
    }
}

感谢您的帮助。

1 个答案:

答案 0 :(得分:1)

只需将&&更改为and -

即可
%dw 1.0
%output application/xml skipNullOn="everywhere"
%namespace soapenv http://schemas.xmlsoap.org/soap/envelope/
---
{
    soapenv#Envelope:{
        soapenv#body:{
            component:{
                coverageClassCode:payload.root.risk.NCD.CI.CD when payload.root.risk.Category == '02' and payload.root.risk.NCD.CoverCode == 'B05' otherwise "",
                //payload.root.risk.NCD.CI.CD when payload.root.risk.Category == '02' && payload.root.risk.NCD.CoverCode == 'B05' otherwise "" ,
                blockedDr:"N"
            }
        }
    }

}