Page 1 of 1

How do I add conditions to xslt?

Posted: Mon Aug 05, 2019 7:25 pm
by winkimjr2
I have a xslt that I need help with.
How do I check CompDate has an @Op of E or A?
OR
TimeStampChange is the only element with @Op code
AND CaseEvent has no CompDate child element

i.e. \Integration\Case\CaseEvent\TimeStampChange@Op='E' and CompDate does not exist

Here is the xml that I am reading

Code: Select all

<Integration>
	<Case xmlns:user="http://tylertechnologies.com" InternalID="1625030311" ID="18482530">
		<CaseEvent xmlns:reslib="urn:reslib" Op="E" Date="08/01/2019" ID="252950987" InternalEventID="1851141172">
			<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>
			<EventType Word="NOPERWELL">Report</EventType>
		</CaseEvent>
	</Case>
	<IntegrationConditions>
		<IntegrationCondition Word="MMGUPD" Description="MMG Updates">
			<NotificationEvent notificationType="MMGUpdate" elementState="Add" elementName="CaseEvent" >Testing</NotificationEvent>
		</IntegrationCondition>
	</IntegrationConditions>
</Integration>
Here is my xslt code

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
	<xsl:output method="xml" encoding="UTF-8" omit-xml-declaration="yes"/>
	<xsl:template match="CaseEvent">
		<xsl:if test="((@Op='E') and ((EventType/@Word='NOPERWELL') or (EventType/@Word='NORIGHTS')) and ((CompDate[@Op='E']) or (CompDate[@Op='A'])))">
			<NotificationEvent notificationType="MMGUpdate">
				<xsl:text>Testing</xsl:text>
			</NotificationEvent>
		</xsl:if>
	</xsl:template>
</xsl:stylesheet>

Re: How do I add conditions to xslt?

Posted: Thu Aug 29, 2019 11:21 am
by Oleksii
Hi!
i.e. \Integration\Case\CaseEvent\TimeStampChange@Op='E' and CompDate does not exist
If you want to test if child nodes of CaseEvent not exist you might use this test:

Code: Select all

 not(TimestampChange[@Op='E'] and CompDate)
But here
How do I check CompDate has an @Op of E or A?
OR
TimeStampChange is the only element with @Op code
AND CaseEvent has no CompDate child element
you are asking fo something else. Also your XSLT test ist something else.

BTW, little syntax improvement: Instead of

Code: Select all

 ((CompDate[@Op='E']) or (CompDate[@Op='A']))
you may use

Code: Select all

CompDate[@Op=('E', 'A')]
best Oleksii