【问题标题】:Mule ESB: How to do Condition checking in Datamapper using XpathMule ESB:如何使用 Xpath 在 Datamapper 中进行条件检查
【发布时间】:2014-09-16 23:41:37
【问题描述】:

我在 xpath 中遇到问题-我需要检查两个属性值,如果条件满足需要对我自己的值进行硬编码。下面是我的xml。

我需要检查 subroot 内部的条件,如果 ItemType=Table1 和 ItemCondition=Chair1,那么我必须提供一个硬编码值“Proceed”(这个硬编码值我将映射到 datamapper 的目标端)。

  <Root>
  <SubRoot>
      <ItemType>Table1</ItemType>
      <ItemCondition>Chair1</ItemCondition>
      <ItemValue>
          .......
       </ItemValue>
  </SubRoot>
  <SubRoot>
      <ItemType>Table2</ItemType>
       <ItemCondition>chair2</ItemCondition>
       <ItemValue>
           .......
       </ItemValue>
   </SubRoot>

       ....Will have multiple subroot
   </Root>

我试图定义如下规则,但它抛出错误

  Type: String
  Context:/Root
  Xpath:    substring("Proceed", 1 div boolean(/SubRoot[ItemType="Table1" and ItemCondition="Chair1"]))

但它会抛出类似的错误

  net.sf.saxon.trans.XPathException: Arithmetic operator is not defined for arguments of types (xs:integer, xs:boolean)

有没有其他快捷方式来执行此操作。请你帮帮我,我已经付出了更多的努力。无法解决它。提前致谢。

【问题讨论】:

    标签: mule mule-studio mule-component


    【解决方案1】:

    我不确定你在哪里应用这个,但你正在寻找的 XPath 表达式是:

    fn:contains(/Root/SubRoot[2]/ItemCondition, "chair") and fn:contains(/Root/SubRoot[2]/ItemType, "Table")
    

    下面是一个适当返回“继续”或“停止”的示例:

    if (fn:contains(/Root/SubRoot[1]/ItemCondition, "Chair") and fn:contains(/Root/SubRoot[2]/ItemType, "Table")) then 'Proceed' else 'Stop'
    

    【讨论】:

    • 谢谢你的回复逻辑。它帮助我解决解决方案的其他想法
    【解决方案2】:

    为了实现上述条件,我最初在 xpath 中很累,给了我很多错误。我在数据映射器的脚本部分通过简单的 if else 条件实现了

     if ( (input.ItemType == 'Table') and (input.ItemCondition == 'chair')) { 
    
        output.Item = 'Proceed'}
        else  { 
    
        output.Item = 'Stop '};
    
    1. 确保您的优先级。例如,在 xml 结构(或转换后的 POJO)中,必须先检查 ItemType,然后再检查 ItemCondition。
    2. && 似乎不适合我,改为“和”运算符

    如果您是第一次尝试实现该逻辑。它可能会帮助你。

    【讨论】:

      猜你喜欢
      • 2014-09-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-11-30
      • 1970-01-01
      相关资源
      最近更新 更多