How do I add a condition to NotificationEvents?

Here should go questions about transforming XML with XSLT and FOP.
winkimjr2
Posts: 55
Joined: Thu Jun 26, 2014 9:00 pm

How do I add a condition to NotificationEvents?

Post by winkimjr2 » Thu Feb 07, 2019 7:57 pm

I need help to add a condition to my xslt. What I need is a condition for all NotificationEvents to have a HearingType/@Word='ACT' How do I do it?

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="/">
<xsl:apply-templates select="Integration/Case/Hearing"/>
</xsl:template>
<xsl:template match="Hearing">
<!-- Set variable for Hearing ID -->
<xsl:variable name="vID">
<!--Get Hearing ID-->
<xsl:value-of select="@ID"/>
</xsl:variable>
<xsl:choose>
<xsl:when test="(@Op='A') and (HearingType/@Op='A') and (HearingType/@Word='ACT')">
<NotificationEvent notificationType="PrepareHearingDocument">
<xsl:attribute name="elementState">New</xsl:attribute>
<xsl:attribute name="elementName">Hearing</xsl:attribute>
<xsl:attribute name="elementKey"><xsl:value-of select="$vID"/><!--Get ID equal to ID from Hearing--></xsl:attribute>
<xsl:text>HearingScheduled</xsl:text>
</NotificationEvent>
</xsl:when>
<xsl:when test="@Op='D' and count(Setting/CourtroomMinutes/HearingResult/@Word)=0">
<NotificationEvent notificationType="PrepareHearingDocument">
<xsl:attribute name="elementState">New</xsl:attribute>
<xsl:attribute name="elementName">Hearing</xsl:attribute>
<xsl:attribute name="elementKey"><xsl:value-of select="$vID"/></xsl:attribute>
<xsl:text>HearingDeleted</xsl:text>
</NotificationEvent>
</xsl:when>
<!--HearingDeleted-->
<xsl:when test="(@Op='E') and (string-length(CancelledReason)!=0) and (CancelledReason/@Op='E')">
<NotificationEvent notificationType="PrepareHearingDocument">
<xsl:attribute name="elementState">New</xsl:attribute>
<xsl:attribute name="elementName">Hearing</xsl:attribute>
<xsl:attribute name="elementKey"><xsl:value-of select="$vID"/></xsl:attribute>
<xsl:text>HearingCancelled</xsl:text>
</NotificationEvent>
</xsl:when>
<!--HearingCancelled-->
<xsl:otherwise>
<xsl:if test="(HearingType/@Op='E')">
<NotificationEvent notificationType="PrepareHearingDocument">
<xsl:attribute name="elementState">New</xsl:attribute>
<xsl:attribute name="elementName">Hearing</xsl:attribute>
<xsl:attribute name="elementKey"><xsl:value-of select="$vID"/></xsl:attribute>
<xsl:text>HearingModified</xsl:text>
</NotificationEvent>
</xsl:if>
<!--HearingModified-->
<xsl:for-each select="Setting[@Op='A']">
<NotificationEvent notificationType="PrepareHearingDocument">
<xsl:attribute name="elementState">New</xsl:attribute>
<xsl:attribute name="elementName">Setting</xsl:attribute>
<xsl:attribute name="elementKey"><xsl:value-of select="$vID"/></xsl:attribute>
<xsl:attribute name="subElementKey"><xsl:value-of select="@ID"/></xsl:attribute>
<xsl:text>SettingScheduled</xsl:text>
</NotificationEvent>
</xsl:for-each>
<!--SettingScheduled-->
<xsl:for-each select="Setting[@Op='E']">
<xsl:if test="string-length(RescheduledType)!=0">
<NotificationEvent notificationType="PrepareHearingDocument">
<xsl:attribute name="elementState">Existing</xsl:attribute>
<xsl:attribute name="elementName">Setting</xsl:attribute>
<xsl:attribute name="elementKey"><xsl:value-of select="$vID"/></xsl:attribute>
<xsl:attribute name="subElementKey"><xsl:value-of select="@ID"/></xsl:attribute>
<xsl:text>SettingRescheduled</xsl:text>
</NotificationEvent>
</xsl:if>
<!--SettingRescheduled-->
<xsl:choose>
<xsl:when test="(string-length(CancelledReason)!=0) and (CancelledReason/@Op='E')">
<NotificationEvent notificationType="PrepareHearingDocument">
<xsl:attribute name="elementState">Existing</xsl:attribute>
<xsl:attribute name="elementName">Setting</xsl:attribute>
<xsl:attribute name="elementKey"><xsl:value-of select="$vID"/></xsl:attribute>
<xsl:attribute name="subElementKey"><xsl:value-of select="@ID"/></xsl:attribute>
<xsl:text>SettingCancelled</xsl:text>
</NotificationEvent>
</xsl:when>
<!--SettingCancelled-->
<xsl:when test="(Cancelled='True') and (string-length(RescheduledReason)=0)">
<NotificationEvent notificationType="PrepareHearingDocument">
<xsl:attribute name="elementState">Existing</xsl:attribute>
<xsl:attribute name="elementName">Setting</xsl:attribute>
<xsl:attribute name="elementKey"><xsl:value-of select="$vID"/></xsl:attribute>
<xsl:attribute name="subElementKey"><xsl:value-of select="@ID"/></xsl:attribute>
<xsl:text>SettingCancelled</xsl:text>
</NotificationEvent>
</xsl:when>
<!--SettingCancelled-->
<xsl:when test="(StartTime/@Op='E') or (EndTime/@Op='E') or (InterpreterNeeded/@Op='E') or (Interpreter/@Op='E') or (CourtSessionBlock/StartTime/@Op='E') or (CourtSessionBlock/EndTime/@Op='E')">
<NotificationEvent notificationType="PrepareHearingDocument">
<xsl:attribute name="elementState">Existing</xsl:attribute>
<xsl:attribute name="elementName">Setting</xsl:attribute>
<xsl:attribute name="elementKey"><xsl:value-of select="$vID"/></xsl:attribute>
<xsl:attribute name="subElementKey"><xsl:value-of select="@ID"/></xsl:attribute>
<xsl:text>SettingModified</xsl:text>
</NotificationEvent>
</xsl:when>
<!--SettingModified-->
</xsl:choose>
</xsl:for-each>
<xsl:for-each select="Setting/CourtroomMinutes">
<xsl:if test="(@Op='E') and (count(*[name(.)!='HearingResult'][@Op='E'])!=0) and (string-length(HearingResult/@Op)=0)">
<NotificationEvent notificationType="PrepareHearingDocument">
<xsl:attribute name="elementState">Existing</xsl:attribute>
<xsl:attribute name="elementName">Setting</xsl:attribute>
<xsl:attribute name="elementKey"><xsl:value-of select="$vID"/></xsl:attribute>
<xsl:attribute name="subElementKey"><xsl:value-of select="../@ID"/></xsl:attribute>
<xsl:text>SettingHeldModified</xsl:text>
</NotificationEvent>
</xsl:if>
<!--SettingHeldModified-->
<!--Setting Held-->
<xsl:if test="((@Op='A') or (@Op='E')) and (HearingResult/@Op='E') and ((HearingResult='Held') or (HearingResult/@Word='CNVOCCUR'))">
<NotificationEvent notificationType="PrepareHearingDocument">
<xsl:attribute name="elementState">Existing</xsl:attribute>
<xsl:attribute name="elementName">Setting</xsl:attribute>
<xsl:attribute name="elementKey"><xsl:value-of select="$vID"/></xsl:attribute>
<xsl:attribute name="subElementKey"><xsl:value-of select="../@ID"/></xsl:attribute>
<!--Setting Held-->
<xsl:text>SettingHeld</xsl:text>
</NotificationEvent>
</xsl:if>
<!--SettingHeld-->
<xsl:if test="(@Op='D')">
<NotificationEvent notificationType="PrepareHearingDocument">
<xsl:attribute name="elementState">Existing</xsl:attribute>
<xsl:attribute name="elementName">Setting</xsl:attribute>
<xsl:attribute name="elementKey"><xsl:value-of select="$vID"/></xsl:attribute>
<xsl:attribute name="subElementKey"><xsl:value-of select="../@ID"/></xsl:attribute>
<xsl:text>SettingHeldReversed</xsl:text>
</NotificationEvent>
</xsl:if>
<!--SettingHeldReversed-->
</xsl:for-each>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>

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

Re: How do I add a condition to NotificationEvents?

Post by Radu » Fri Feb 08, 2019 11:16 am

Hi,

It's quite hard to tell without having a sample XML file to test your XSLT stylesheet against.
If you want to forcefully stop the XSLT processing when a certain condition is not fulfilled you can do something like:

Code: Select all

<xsl:if test="HearingType[not(@Word='ACT')]"><xsl:message terminate="yes">The required attribute was not present.</xsl:message></xsl:if>
Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com

Post Reply