cancel
Showing results for 
Search instead for 
Did you mean: 

XPath expression to check 2 fields in the same grandparents node

suwandi_cahyadi
Contributor
0 Kudos

Dear Expert,

I need to put a condition at my Receiver Determination.

The coming data element can have structure like this:

<body>

        <receiver>

              <id>0</id>

        </receiver>

       <details>

          <loc> </loc>

       </details>

</body>

The coming file could have more than one body.

Now I need to check, if there exist, in the same body, the id = 0 AND loc is not space " ".

I use the following XPath:

/Message/Body/receive[id = "0"]                                        EX                         AND

/Message/Body/details[loc != " "]

Now the XPath expression fails for the following condition:

<body>

       <receiver>

             <id>0</id>

       </receiver>

       <details>

          <loc> </loc>

       </details>

</body>         

<body>

       <receiver>

             <id>5</id>

       </receiver>

       <details>

          <loc>A</loc>

       </details>

</body>



This is because the expression only checks if there's any posid EQ 0 anywhere, and the location_of_goods equals A anywhere. What I want to achieve is to check if the posid = 0 AND location_of_goods is not space in the same body.

Any advice is appreciated.

Thank you,

Suwandi C.

Accepted Solutions (1)

Accepted Solutions (1)

markangelo_dihiansan
Active Contributor
0 Kudos

Hello,


/Message/Body/receive[id = "0"]                                        EX                         AND

/Message/Body/details[loc != " "]

Now the XPath expression fails for the following condition:

<body>

       <receiver>

             <id>0</id>

       </receiver>

       <details>

          <loc> </loc>

       </details>

</body>         

<body>

       <receiver>

             <id>5</id>

       </receiver>

       <details>

          <loc>A</loc>

       </details>

</body>

/Message/Body[(receiver/id = "0") and (details/loc != " ")]

http://scn.sap.com/community/pi-and-soa-middleware/blog/2006/06/07/customise-your-xpath-expressions-...

Hope this helps,

Mark

Answers (2)

Answers (2)

anupam_ghosh2
Active Contributor
0 Kudos

Hi Suwandi,

                       Could you please try this logic

/Message/Body[0]/receive[id = "0"]                                        EX                         AND

/Message/Body[0]/details[loc != " "]


OR


/Message/Body[1]/receive[id = "0"]                                        EX                         AND

/Message/Body[1]/details[loc != " "]



Regards

Anupam

iaki_vila
Active Contributor
0 Kudos

Hi Suwandi,

I think there is a misunderstood about the boolean logic,

If you want to send your message when id is equal to zero and loc field is a blank, try with this:


/Message/Body/receive[id = "0"]                                                               AND

/Message/Body/details[loc = " "]

Also, you can check this condition in mapping, you could create a dummy field only for PI usage, like /Message/Body/error and to map here the result of the comparative and to make an easy XPATH in the configuration.


Regards.