0
votes

i'm facing issue in xpath-I need do a check two attribute values, if the condition satisfies need to do hard code my own value. Below is my xml.

I need to check the condition like inside subroot- if ItemType=Table1 and ItemCondition=Chair1 then i have to give a hard coded value 'Proceed'( this hard coded value i will map to target side of 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>

I have tried to define rules as below, but it is throwing error

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

But it is throwing error like

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

Is there any other shortcut way to perform this.Could you please help me, i have given lot more effort. Not able to resolve it. Thanks in advance.

2

2 Answers

1
votes

I am not sure where you are applying this but the XPath expression you are looking for is:

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

So here is an example returning "Proceed" or "Stop" as appropriate:

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

To implement the above condition , i was initially tired to do in xpath, gave me lot of error. I have implemented by simple if else condition in script part of data mapper

 if ( (input.ItemType == 'Table') and (input.ItemCondition == 'chair')) { 

    output.Item = 'Proceed'}
    else  { 

    output.Item = 'Stop '};
  1. Make sure about your precedence. Example, Here in the xml structure( or converted POJO) ItemType has to be checked first then followed with ItemCondition.
  2. && not seems to be working for me, change to 'and' operator

If you were first time trying to implement the logic. It may help you.