Click here to Skip to main content
15,880,469 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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

XML
<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>


What I have tried:

Here is my xslt code. I need help adding and condition to also check if any other child nodes in CaseEvent have Op code
The XML above should return false because both TimeStampChange and CompDate has @OP. It should only return true when only TimeStampChange as @Op or when TimeStampChange has no @Op but CompDate has @Op

My if statement is returning true.

XML
<xsl:if test="(@Op='E') and (((CompDate[@Op='A']) or (CompDate[@Op='E'])) or (TimestampChange[@Op='E'] and count(*[@Op])=1))">True</xsl:if>
Posted
Updated 8-Aug-19 17:51pm
v9

1 solution

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


EDIT: Based on your updated question and comment, I'm guessing that you want the following:
  • If CompDate[@Op] is either "E" or "A", then the statement is true if and only if TimestampChange has no Op attribute, regardless of whether or not the other nodes have an Op attribute;
  • Otherwise, the statement is true if any only if TimestampChange is the only node with an Op attribute;

XML
<xsl:if test="((CompDate[@Op='E'] or CompDate[@Op='A']) and TimestampChange and count(TimestampChange[@Op])=0) or (TimestampChange[@Op] and count(*[@Op])=1)" >True</xsl:if>
 
Share this answer
 
v2
Comments
Member 11403304 8-Aug-19 23:35pm    
That seems to work. However there are new requirements given to me by the project owner. I need to also check if CompDate has Op="E" or "A". If CompDate[@Op="A"] or CompDate[@Op="E"] then its true as long as TimeStampChange has no @Op. I add code to the one you gave me but it is returning true when it should return false for the XML above. XML Above should return false. Here is what I added. <xsl:if test="(@Op='E') and (((CompDate[@Op='A']) or (CompDate[@Op='E'])) or (TimestampChange[@Op='E'] and count(*[@Op])=1))">

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900