我试图从一个更大的集合中选择某个XML,使用一个过滤器来只获得具有正确属性的那个。
如果没有过滤器,我会接收当前集合中的每一项,但就是想不出过滤器的正确语法……
我的XML-data:
<customer>
<profile>
<custom-attributes>
<custom-attribute attribute-id="customerCredit">0.0</custom-attribute>
<custom-attribute attribute-id="customerIDS">12345</custom-attribute>
<custom-attribute attribute-id="sscid">00001</custom-attribute>
</custom-attributes>
/<profile>
</customer>我的数据编织过滤器:
payload.ns0#customers.*ns0#customer map ( customer , indexOfCustomer ) -> {
(customer.ns0#profile.*ns0#"custom-attributes" filter ($.ns0#"custom-attribute".@"attribute-id" == "customerIDS") map {
"keys" : $
}
) 对于上面的例子,我希望收到“key: 12345”,但由于过滤器的原因,它被简单地跳过了。
发布于 2019-05-23 23:18:14
您的输入与您的dw脚本不匹配,因此很难判断,没有名称空间,并且缺少"customers“元素。
但是基于你的输入和输出,你可以通过一个过滤器来实现它:
%dw 2.0
output application/json
---
payload.*customer map {
keys: $.profile."custom-attributes".*"custom-attribute" filter($.@"attribute-id"=="customerIDS")
}输出:
[
{
"keys": [
"12345"
]
}
]或者根据您的示例,也不需要使用map:
%dw 2.0
output application/json
---
keys: payload.customer.profile."custom-attributes".*"custom-attribute" filter($.@"attribute-id"=="customerIDS")如果您提供您期望的更详细的输入和输出,我们可以提供更多帮助。
https://stackoverflow.com/questions/56275951
复制相似问题