【问题标题】:Mule - finding the sum of the values of xml elementsMule - 查找 xml 元素的值的总和
【发布时间】:2017-08-28 08:31:11
【问题描述】:

我需要在 mule 中找到 xml 元素的总和。输入 xml 如下所示:

<message:MessageGroup
xmlns:message="http://www.SDMX.org/resources/SDMXML/schemas/v2_0/message"
xmlns="http://www.SDMX.org/resources/SDMXML/schemas/v2_0/generic"
xmlns:common="http://www.SDMX.org/resources/SDMXML/schemas/v2_0/common"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.SDMX.org/resources/SDMXML/schemas/v2_0/generic http://www.sdmx.org/docs/2_0/SDMXGenericData.xsd http://www.SDMX.org/resources/SDMXML/schemas/v2_0/message http://www.sdmx.org/docs/2_0/SDMXMessage.xsd">
<Header xmlns="http://www.SDMX.org/resources/SDMXML/schemas/v2_0/message">
    <ID>none</ID>
    <Test>false</Test>
    <Truncated>false</Truncated>
    <Prepared>2017-08-28T05:35:50</Prepared>
    <Sender id="ABS">
        <Name xml:lang="en">Australian Bureau of Statistics</Name>
        <Name xml:lang="fr">Australian Bureau of Statistics</Name>
    </Sender>
</Header>
<DataSet
    keyFamilyURI="http://stat.data.abs.gov.au/restsdmx/sdmx.ashx/GetKeyFamily/CPI">
    <KeyFamilyRef>CPI</KeyFamilyRef>
    <Series>
        <SeriesKey>
            <Value concept="MEASURE" value="3" />
            <Value concept="REGION" value="50" />
            <Value concept="INDEX" value="10001" />
            <Value concept="TSEST" value="10" />
            <Value concept="FREQUENCY" value="Q" />
        </SeriesKey>
        <Attributes>
            <Value concept="TIME_FORMAT" value="P3M" />
        </Attributes>
        <Obs>
            <Time>2001-Q1</Time>
            <ObsValue value="6" />
        </Obs>
        <Obs>
            <Time>2001-Q2</Time>
            <ObsValue value="6.1" />
        </Obs>
        <Obs>
            <Time>2001-Q3</Time>
            <ObsValue value="2.5" />
        </Obs>
        <Obs>
            <Time>2001-Q4</Time>
            <ObsValue value="3.1" />
        </Obs>
        <Obs>
            <Time>2002-Q1</Time>
            <ObsValue value="3" />
        </Obs>
        <Obs>
            <Time>2002-Q2</Time>
            <ObsValue value="2.8" />
        </Obs>
        <Obs>
            <Time>2002-Q3</Time>
            <ObsValue value="3.2" />
        </Obs>
        <Obs>
            <Time>2002-Q4</Time>
            <ObsValue value="2.9" />
        </Obs>
            </Series>
    <Annotations>
        <common:Annotation>
            <common:AnnotationTitle>Statistical usage warning
            </common:AnnotationTitle>
            <common:AnnotationText>
                ABS.Stat beta is continuing to be developed. Data will be updated as soon
                as possible following its 11:30 am release on the ABS website.
            </common:AnnotationText>
        </common:Annotation>
    </Annotations>
</DataSet>

这里我需要对元素进行总和:,其中包含:MessageGroup.DataSet.Series.*Obs。尝试使用 dataweave 但不成功。在使用 dataweave 时,我无法评估 .任何帮助将不胜感激。

【问题讨论】:

    标签: mule dataweave


    【解决方案1】:

    因为值是 ObsValue 标记的属性,所以使用 @ 符号来获取属性值,例如,

    %dw 1.0
    %output application/java
    ---
    sum (payload.MessageGroup.DataSet.Series.*Obs.ObsValue.@value)
    

    输出 = 29.6

    希望对你有帮助

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-07-15
      • 2018-11-03
      • 1970-01-01
      • 1970-01-01
      • 2018-02-02
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多