How do I fix xslt if condition?

Questions about XML that are not covered by the other forums should go here.
winkimjr2
Posts: 62
Joined: Thu Jun 26, 2014 9:00 pm

How do I fix xslt if condition?

Post by winkimjr2 » Wed Jul 03, 2019 12:40 am

I have a simple xml document. I want to check if UserID is not equal to IntegrationAdmin or Integration_Admin
My xslt is
Here is the sample xml document

Code: Select all

<Integration xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:tsg="http://tsgweb.com" xmlns:IXML="http://tsgweb.com" xmlns="">
	<ControlPoint Timestamp="7/2/2019 2:30:42 PM" UserID="Deuua">SAVE-PR-EVENT</ControlPoint>
		<CaseEvent xmlns:reslib="urn:reslib" Date="06/14/2019" ID="252945065" InternalEventID="1851137353">
			<EventType Word="NOPERWELL">Personal Well-being Report [R]</EventType>
		</CaseEvent>
		<CaseEvent xmlns:reslib="urn:reslib" Date="06/14/2019" ID="252945066" InternalEventID="1851137354">
			<EventType Word="NORIGHTS">Annual Notice of Rights [R]</EventType>
		</CaseEvent>
	</Case>
	<IntegrationConditions>
		<IntegrationCondition Word="TRUE" Description="Always True">
			<ControlPoint Timestamp="7/2/2019 2:30:42 PM" UserID="Deuua">SAVE-PR-EVENT</ControlPoint>
		</IntegrationCondition>
	</IntegrationConditions>
</Integration>
Expected result

Code: Select all

<NotificationEvent notificationType="MMGUpdate" elementState="Add" elementName="CaseEvent" elementKey="252945069">InsertPWBRorAOS</NotificationEvent>

However my code is return nothing.

Here is the xslt that is not processing as I expect it to The problem is the if statement with or. Can someone help me?

Code: Select all

<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="/">
		<xsl:if test="Integration/ControlPoint='SAVE-PR-EVENT'">
			<xsl:apply-templates select="Integration/Case/CaseEvent"/>
		</xsl:if>
	</xsl:template>
	<xsl:template match="CaseEvent">
		<xsl:if test="((//Integration/ControlPoint/@UserID!='IntegrationAdmin') or (//Integration/ControlPoint/@UserID!='Integration_Admin'))">
			<xsl:if test="(@Op='E') and ((EventType/@Word='NOPERWELL') or (EventType/@Word='NORIGHTS'))">
				<NotificationEvent notificationType="MMGUpdate">
					<xsl:attribute name="elementState">Add</xsl:attribute>
					<xsl:attribute name="elementName">CaseEvent</xsl:attribute>
					<xsl:attribute name="elementKey"><xsl:value-of select="@ID"/></xsl:attribute>
					<xsl:text>InsertPWBRorAOS</xsl:text>
				</NotificationEvent>
			</xsl:if>
		</xsl:if>
	</xsl:template>
</xsl:stylesheet>

Radu
Posts: 6541
Joined: Fri Jul 09, 2004 5:18 pm

Re: How do I fix xslt if condition?

Post by Radu » Wed Jul 03, 2019 10:37 am

Hi,

So an xsl:if like this:

Code: Select all

<xsl:if test="(@Op='E') and ((EventType/@Word='NOPERWELL') or (EventType/@Word='NORIGHTS'))">
means that the "Op" attribute must be set to "E" AND either the "Word" attribute is set to "NOPERWELL" or "NORIGHTS".
So as you are missing the "Op='E'" attribute on the "CaseEvent" element, the xsl:if condition is not fulfilled.

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com

winkimjr2
Posts: 62
Joined: Thu Jun 26, 2014 9:00 pm

Re: How do I fix xslt if condition?

Post by winkimjr2 » Wed Jul 03, 2019 10:37 pm

I think I had posted wrong xml document. Here is the correct xml document code

Code: Select all

<Integration xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:tsg="http://tsgweb.com" xmlns="">
	<ControlPoint Timestamp="7/2/2019 3:38:03 PM" UserID="IntegrationAdmin">SAVE-PR-EVENT</ControlPoint>
	<Case xmlns:user="http://tylertechnologies.com" InternalID="1625030039" ID="18482188">
		<CaseEvent xmlns:reslib="urn:reslib" Op="E" Date="06/14/2019">
			<EventType Word="NOPERWELL">Personal Well-being Report [R]</EventType>
		</CaseEvent>
	</Case>
	<IntegrationConditions>
		<IntegrationCondition Word="TRUE" Description="Always True">
			<ControlPoint Timestamp="7/2/2019 3:38:03 PM" UserID="Deea">SAVE-PR-EVENT</ControlPoint>
		</IntegrationCondition>
	</IntegrationConditions>
</Integration>

winkimjr2
Posts: 62
Joined: Thu Jun 26, 2014 9:00 pm

Re: How do I fix xslt if condition?

Post by winkimjr2 » Wed Jul 03, 2019 10:49 pm

I think my solution is this
<xsl:if test="((/Integration/ControlPoint/@UserID!='Integration_Admin') and (/Integration/ControlPoint/@UserID!='IntegrationAdmin'))">

I should not use the word or between the two conditions.

Post Reply