Skip to main content
Announcements
A fresh, new look for the Data Integration & Quality forums and navigation! Read more about what's changed.
cancel
Showing results for 
Search instead for 
Did you mean: 
alevy
Specialist

Xpath to use alternate element value if preferred value is nilled

I'm receiving XML as follows:

<Events xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <EventDetails>
    <AccountingDate>2017-01-01</AccountingDate>
    <PaymentDate>2017-01-31</PaymentDate>
  </EventDetails>
  <EventDetails>
    <PaymentDate>2017-01-31</PaymentDate>
    <AccountingDate>2017-01-01</AccountingDate>
  </EventDetails>
  <EventDetails>
    <AccountingDate>2017-01-01</AccountingDate>
    <PaymentDate xsi:nil="true"/>
  </EventDetails>
</Events>

 

I need to extract the PaymentDate if it exists but otherwise substitute the AccountingDate.

 

Can anyone please help with an Xpath expression that will achieve this for me? (It must be done in the Xpath rather than after the tExtractXMLfield component as the actual parsing logic is externally sourced.)

Labels (3)
1 Solution

Accepted Solutions
alevy
Specialist
Author

Finally solved it after about 4 hours...

concat(substring(PaymentDate,   1 div    (boolean(PaymentDate) and PaymentDate!='')),
       substring(AccountingDate,1 div not(boolean(PaymentDate) and PaymentDate!='')))

(It also caters for the possibility that PaymentDate doesn't exist at all although in my case it always does.)

 

Now I just need to make it work with three possible dates!

View solution in original post

4 Replies
alevy
Specialist
Author

Finally solved it after about 4 hours...

concat(substring(PaymentDate,   1 div    (boolean(PaymentDate) and PaymentDate!='')),
       substring(AccountingDate,1 div not(boolean(PaymentDate) and PaymentDate!='')))

(It also caters for the possibility that PaymentDate doesn't exist at all although in my case it always does.)

 

Now I just need to make it work with three possible dates!

Anonymous
Not applicable

Is that an XPath query ?"concat(substring(PaymentDate,   1 div    (boolean(PaymentDate) and PaymentDate!='')),
       substring(AccountingDate,1 div not(boolean(PaymentDate) and PaymentDate!='')))"

is there any way that we can join multiple fields in a different loop from same XML file ?  to get the desired out put ?

alevy
Specialist
Author

Yes, it is.

You should post a new question, with example of your XML and the result you want to achieve.

Anonymous
Not applicable

Glad to see you back Adam! 0683p000009MACn.png

 

Elisa