我已经拆分了我的一个领域,想通过每个重复仅显示1条记录来区分它。例如,如果有5个id ='abc',则结果中只会显示1个id ='abc'。
基于下面的示例输出,如何区分仅显示1个ABC123而不显示2个ABC123?
我已经完全删除了输出中的FruitTypeCode字段,是否可以知道导致该错误的原因?
样本输入
<GetListOfCategoriesDetailResponse xmlns="" xmlns:s="">
<GetListOfCategoriesDetailResult xmlns:a="" xmlns:i="">
<a:CategoryDetail>
<a:Category>ABC123 Kook</a:Category>
<a:CategoryClass>Apple</a:CategoryClass>
<a:FruitTypeGrouping/>
</a:CategoryDetail>
<a:CategoryDetail>
<a:Category>ABC123 Loop</a:Category>
<a:CategoryClass>Apple</a:CategoryClass>
<a:FruitTypeGrouping/>
</a:CategoryDetail>
<a:CategoryDetail>
<a:Category>BCD344 78JL</a:Category>
<a:CategoryClass>Apple</a:CategoryClass>
<a:FruitTypeGrouping/>
</a:CategoryDetail>
</GetListOfCategoriesDetailResult>
</GetListOfCategoriesDetailResponse>
电流输出
<ns0:FoodProducts>
<ns0:FoodProduct>
<ns0:FruitTypes>
<ns0:FruitType FruitTypeCode="ABC123" FruitTypeName="Apple" FruitTypeGroup="">
<ns0:Descriptions>
<ns0:Description>
<ns0:Text>This is sweet</ns0:Text>
</ns0:Description>
</ns0:Descriptions>
</ns0:FruitType>
<ns0:FruitType FruitTypeCode="ABC123" FruitTypeName="Apple" FruitTypeGroup="">
<ns0:Descriptions>
<ns0:Description>
<ns0:Text>This is not sweet</ns0:Text>
</ns0:Description>
</ns0:Descriptions>
</ns0:FruitType>
<ns0:FruitType FruitTypeCode="BCD344" FruitTypeName="Apple" FruitTypeGroup="">
<ns0:Descriptions>
<ns0:Description>
<ns0:Text></ns0:Text>
</ns0:Description>
</ns0:Descriptions>
</ns0:FruitType>
</ns0:FoodProduct>
</ns0:FoodProducts>
预期产量
<ns0:FoodProducts>
<ns0:FoodProduct>
<ns0:FruitTypes>
<ns0:FruitType FruitTypeCode="ABC123" FruitTypeName="Apple" FruitTypeGroup="">
<ns0:Descriptions>
<ns0:Description>
<ns0:Text>This is sweet</ns0:Text>
</ns0:Description>
</ns0:Descriptions>
</ns0:FruitType>
<ns0:FruitType FruitTypeCode="BCD344" FruitTypeName="Apple" FruitTypeGroup="">
<ns0:Descriptions>
<ns0:Description>
<ns0:Text></ns0:Text>
</ns0:Description>
</ns0:Descriptions>
</ns0:FruitType>
</ns0:FoodProduct>
</ns0:FoodProducts>
到目前为止我的数据编织代码
%output application/xml
%namespace ns0
%namespace ns01
%namespace ns1
---
{
ns0#FoodProductRS: {
ns0#FoodProducts: {
ns0#FoodProduct: {
ns0#FruitTypes: {
((payload.ns01#GetListOfCategoriesDetailResponse.ns01#GetListOfCategoriesDetailResult.*ns1#CategoryDetail filter $.ns1#CategoryClass == "Apple" map ((categoryDetail , indexOfCategoryDetail) -> {
ns0#FruitType @(FruitTypeCode: (categoryDetail.ns1#Category splitBy " ")[0], FruitTypeName: categoryDetail.ns1#CategoryClass , FruitTypeGroup: categoryDetail.ns1#FruitTypeGrouping): {
ns0#Descriptions: {
ns0#Description: {
ns0#Text: categoryDetail.ns1#LongDescription
}
}
}
})) distinctBy $.ns0#FruitType.@FruitTypeCode)
}
}
}
}
}
答案 0 :(得分:2)
我已经在3.9.2的tried子中尝试了您的脚本,它应该可以工作,但是可悲的是您遇到了一个问题(该问题将在3.9.3中出现)。为了解决该问题,您应该先使distingtyBy。
%output application/xml
%namespace ns0 a
%namespace ns01 a
%namespace ns1 a
---
{
ns0#FoodProductRS: {
ns0#FoodProducts: {
ns0#FoodProduct: {
ns0#FruitTypes: {
(
(payload.ns01#GetListOfCategoriesDetailResponse.ns01#GetListOfCategoriesDetailResult.*ns1#CategoryDetail
filter $.ns1#CategoryClass == "Apple"
distinctBy ($.ns1#Category splitBy " ")[0]
map ((categoryDetail , indexOfCategoryDetail) -> {
ns0#FruitType @(FruitTypeCode: (categoryDetail.ns1#Category splitBy " ")[0], FruitTypeName: categoryDetail.ns1#CategoryClass , FruitTypeGroup: categoryDetail.ns1#FruitTypeGrouping): {
ns0#Descriptions: {
ns0#Description: {
ns0#Text: categoryDetail.ns1#LongDescription
}
}
}
})
)
)
}
}
您使用的是哪种m子版本?