An And
An And

Reputation: 155

Exclude a specific element from selection through XPath in mule-esb transformation

I have a web service response in the below mentioned format. I use xpath to lookup the root element <returnObjs> within mule for transformational purposes. Is there a way to lookup the root element <returnObjs> in such a way that <newElement> element never gets picked up in the xpath lookup ? Please note that <returnObjs> is a list of <returnObj> type and so there could be multiple <returnObj> objects that may/may not have <newElement> element in it.

<ns2:root>    
 <returnObjs>
 <!-- 1 or more repititions -->
 <returnObj>
    <EL1>A</EL1>
    <EL2>B</EL2>
    <Top>
       <TopEl1>data1</TopEl1>
       <TopEl2>data2</TopEl2>
       <TopEl3>data3</TopEl3> 
       <newElement>new value</newElement>
       <Nested>
          <Nested1el1>val1</Nested1el1>
          <Nested1el2 />
          <Nestedel3>val2</Nestedel3>
          <Nestedel4>val3</Nestedel4>
       </Nested>
    </Top>
 </returnObj>
 <returnObjs>
</ns2:root>

Note : I am evaluating /root/*[not(newElement)] but so far it has not worked for me.

Upvotes: 0

Views: 57

Answers (2)

splash58
splash58

Reputation: 26153

If you want select all elements but newElement use xpath

/*[name() != "newElement"]

Upvotes: 0

Ian Roberts
Ian Roberts

Reputation: 122414

No. XPath is a tool for selecting nodes from an XML tree - it can either select a particular returnObj or not select it, but it can't modify the element's content.

You would need a transformation tool such as XSLT in order to build a new XML document based on the incoming one, with the desired elements removed.

Upvotes: 1

Related Questions