How do I add conditions to XSLT if statement
Here should go questions about transforming XML with XSLT and FOP.
-
- Posts: 62
- Joined: Thu Jun 26, 2014 9:00 pm
How do I add conditions to XSLT if statement
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
Here is my xslt code. I need help adding and condition to also check if any other child nodes in CaseEvent have 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>
Code: Select all
<xsl:if test="((TimestampChange[@Op='E']) and ())">True</xsl:if>
-
- Posts: 2879
- Joined: Tue May 17, 2005 4:01 pm
Re: How do I add conditions to XSLT if statement
Hi,
Regards,
Adrian
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
Adrian
Adrian Buza
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
-
- Posts: 62
- Joined: Thu Jun 26, 2014 9:00 pm
Re: How do I add conditions to XSLT if statement
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.
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>
-
- Posts: 2879
- Joined: Tue May 17, 2005 4:01 pm
Re: How do I add conditions to XSLT if statement
Try:
Regards,
Adrian
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))
Adrian
Adrian Buza
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
-
- Posts: 62
- Joined: Thu Jun 26, 2014 9:00 pm
Re: How do I add conditions to XSLT if statement
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.
Jump to
- Oxygen XML Editor/Author/Developer
- ↳ Feature Request
- ↳ Common Problems
- ↳ DITA (Editing and Publishing DITA Content)
- ↳ SDK-API, Frameworks - Document Types
- ↳ DocBook
- ↳ TEI
- ↳ XHTML
- ↳ Other Issues
- Oxygen XML Web Author
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Content Fusion
- ↳ Feature Request
- ↳ Common Problems
- Oxygen JSON Editor
- ↳ Feature Request
- ↳ Common Problems
- Oxygen PDF Chemistry
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Feedback
- ↳ Feature Request
- ↳ Common Problems
- Oxygen XML WebHelp
- ↳ Feature Request
- ↳ Common Problems
- XML
- ↳ General XML Questions
- ↳ XSLT and FOP
- ↳ XML Schemas
- ↳ XQuery
- NVDL
- ↳ General NVDL Issues
- ↳ oNVDL Related Issues
- XML Services Market
- ↳ Offer a Service