1

我正在尝试编写数据编织以在响应 xml 中添加价格。

请求 xml 看起来像

<?xml version="1.0" encoding="UTF-8"?>
<UniversityResponse xmlns="urn:abc:api:Components">
    <Timestamp>2015-12-16T22:05:41.229Z</Timestamp>
    <Dept>IT</Dept>
    <Fees>
        <Fee>
            <Name>John</Name>
            <Fee currencyID="USD">1.0</Fee>
        </Fee>
        <Fee>
            <Name>Enrique</Name>
            <Fee currencyID="USD">3.0</Fee>
        </Fee>
        <Fee>
            <Name>Mary</Name>
            <Fee currencyID="USD">2.0</Fee>
        </Fee>
        <Fee>
            <Name>Meena</Name>
            <Fee currencyID="USD">0.5</Fee>
        </Fee>
    </Fees>
</UniversityResponse>

截至目前,我写了喜欢

%dw 1.0
%namespace ns0 urn:abc:api:Components
%output application/xml
---
TotalFees:{
    plus : payload.ns0#UniversityResponse.ns0#Fees.*ns0#Fee[0].ns0#Fee +
    payload.ns0#UniversityResponse.ns0#Fees.*ns0#Fee[0].ns0#Fee +
    payload.ns0#UniversityResponse.ns0#Fees.*ns0#Fee[1].ns0#Fee +
    payload.ns0#UniversityResponse.ns0#Fees.*ns0#Fee[2].ns0#Fee +
    payload.ns0#UniversityResponse.ns0#Fees.*ns0#Fee[3].ns0#Fee 
}

输出 :

<TotalFees>
  <plus>6.5</plus>
</TotalFees>

如何在响应 xml 中循环复杂标记?

基本上我想为 UniversityResponse/Fees 创建一个循环。在循环内我想写一些像 Plus = Plus + "UniversityResponse/Fees/Fee[counter].Fee"

4

1 回答 1

1

这有点让人头疼,因为我在文档中寻找 SUM 函数,而不是在文档中,但它在语言中:)

--

%dw 1.0
%output application/xml
%namespace ns0 urn:abc:api:Components
---

TotalFees: plus: sum payload.ns0#UniversityResponse.ns0#Fees.*ns0#Fee.ns0#Fee

<?xml version='1.0' encoding='UTF-8'?>
<TotalFees>
  <plus>6.5</plus>
</TotalFees>
于 2015-12-17T14:38:59.290 回答