【问题标题】:XPATH condition to map fields in datamapper映射数据映射器中的字段的 XPATH 条件
【发布时间】:2023-04-06 04:22:01
【问题描述】:

我需要将一个值传递给 datamapper 并将其检索到映射字段。在下面的 InputXML 中,'pages' 元素被重复,如图所示。我的输出应该只包含与输入匹配的 pages 元素的 book 对象。 (即,我通过 myVariable 将 100 作为页面值传递。因此输出应该只有包含 100 页的 book 元素)。

<set-session-variable variableName="myVariable" value="100" />
<data-mapper:transform doc:name="XML To XML" config-ref="xml_to_xml" >
        <data-mapper:input-arguments>
            <data-mapper:input-argument key="myVariable">#[sessionVars.myVariable]</data-mapper:input-argument>
        </data-mapper:input-arguments>
    </data-mapper:transform>

输入XML:

<catalogue>
<books>
 <book>
   <name>book1</name>
   <author>author1</author>
   <pages>100</pages>
 </book>
 <book>
   <name>book2</name>
   <author>author2</author>
   <pages>200</pages>
 </book>
 <book>
   <name>book3</name>
   <author>author3</author>
   <pages>300</pages>
 </book>
</books>
<writeups>
 <a>1</a>
</writeups>
<catalogue>

输出XML:

<catalogue2>
<books>
 <book>
   <name>book1</name>
   <author>author1</author>
   <pages>100</pages>
 </book>

<writeups>
 <a>1</a>
</writeups>
<catalogue2>

方法一:

//Catalogue/books[inputArguments.myVariable=Catalogues/books/book/pages]/book/pages

在页面的 xpath 规则中,我试图选择这样一个具有 pages 值作为传递的输入参数的书籍对象。但是这种方法会抛出一个异常说

org.jetel.exception.JetelRuntimeException: net.sf.saxon.trans.StaticError: Undeclared      variable in a standalone expression

能否请您更正 xpath 表达式?

【问题讨论】:

    标签: xml xpath mule datamapper


    【解决方案1】:

    我认为您不能将输入参数直接用于 XPath 表达式。也许您应该首先使用输入参数将其添加到有效负载(XML)中,然后执行第二个数据映射器,并在第二个转换中使用这个添加的字段:

    http://www.mulesoft.org/documentation/display/33X/Using+Input+Arguments

    【讨论】:

    • @Anton Kupias 你能帮我们解决这个问题吗?
    猜你喜欢
    • 2021-10-13
    • 2022-08-03
    • 2016-12-04
    • 1970-01-01
    • 2017-06-27
    • 2019-02-05
    • 1970-01-01
    • 2020-01-27
    • 2014-10-13
    相关资源
    最近更新 更多