Page 1 of 1

How do I add conditions to XSLT if statement

Posted: Wed Aug 07, 2019 4:45 pm
by winkimjr2
How do I check TimeStampChange node is the only node with Op code
AND in CaseEvent there are no Op codes on any other child nodes? i.e. CaseEvent\TimeStampChange Op="E" and there are no Op codes on any other child elements.

If statement will be True when TimeStampChange is the only node in CaseEvent that have Op code.
If any other node have an Op code, then the If statement will be False

Here is the xml that I am reading

Code: Select all

<Case>
   <CaseEvent Op="E">
      <RevDate Op="E">08/01/2019</RevDate>
      <CompDate Op="E">08/01/2019</CompDate>
      <TimestampChange Op="E">08/01/2019 14:07:15:690</TimestampChange>
   </CaseEvent>
</Case>
Here is my xslt code. I need help adding and condition to also check if any other child nodes in CaseEvent have Op code

Code: Select all

<xsl:if test="((TimestampChange[@Op='E']) and ())">True</xsl:if>

Re: How do I add conditions to XSLT if statement

Posted: Thu Aug 08, 2019 10:35 am
by adrian
Hi,
If statement will be True when TimeStampChange is the only node in CaseEvent that have Op code.

Code: Select all

not(*[name() != 'TimestampChange']/@Op) and TimestampChange/@Op
Regards,
Adrian

Re: How do I add conditions to XSLT if statement

Posted: Fri Aug 09, 2019 7:04 am
by winkimjr2
Hi Adrian, I was also asked to return true when CompDate has @Op="E" or "A". So the above XML should return false because TimeStampChange has an @Op="E" and CompDate has @Op="E".
I tried the following but it is returning true instead of false. Please help.

Code: Select all

<xsl:if test="(@Op='E') and (((CompDate[@Op='A']) or (CompDate[@Op='E'])) or (TimestampChange[@Op='E'] and count(*[@Op])=1))">True</xsl:if>

Re: How do I add conditions to XSLT if statement

Posted: Fri Aug 09, 2019 1:03 pm
by adrian
Try:

Code: Select all

(@Op='E') and (not(TimestampChange[@Op='E']) and ((CompDate[@Op='A']) or (CompDate[@Op='E'])) or (TimestampChange[@Op='E'] and count(*[@Op])=1))
Regards,
Adrian

Re: How do I add conditions to XSLT if statement

Posted: Fri Aug 09, 2019 3:15 pm
by winkimjr2
Thank you so much Adrian. I spent 3 days on this and your code is now working as expected. you have no idea how happy and satisfied I am right now! You are a miracle worker.