0

I would like to get the <CaseEvent> with the most recent <EventDate> My xsl selectot is returning the first CaseEvent even though that is not the most recent CaseEvent based on the EventDate

How do I do it?

Desired output

<NotificationEvent notificationType="DvsDlNotice" elementState="New" elementName="CaseEvent" elementKey="160825565" eventDate="05/12/2015" eventTime="7:36 AM" noticeTypeCode="REIN">Reinstatement - Fail to Appear or Pay</NotificationEvent>

My xml document

<Integration xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:tsg="http://tsgweb.com" xmlns:IXML="http://tsgweb.com" xmlns:CMCodeQueryHelper="urn:CMCodeQueryHelper" PackageID="DL Notice to DVS" MessageID="67094687" xmlns="">
<Case InternalID="1617090455" ID="12124678" xmlns:user="http://tylertechnologies.com">
    <FiledDate>05/11/2015</FiledDate>
    <CaseCategory>CR</CaseCategory>
    <CaseType Word="VIB">Crim/Traf Non-Mand</CaseType>

    <CaseEvent Date="05/11/2015" ID="160825556" InternalEventID="1721874614" xmlns:reslib="urn:reslib">
        <EventDate>05/11/2015</EventDate>
        <EventTime>3:42 PM</EventTime>
        <Docketable>True</Docketable>
        <IncludeOnTrans>True</IncludeOnTrans>
        <RecordingNeeded>false</RecordingNeeded>
        <TimestampCreate>05/11/2015 15:42:23:550</TimestampCreate>
        <Deleted>false</Deleted>
        <AgingClockActionKey Word="N">Does not affect aging clock</AgingClockActionKey>
        <EventType Word="DLSUSFTP">DL suspension request to DPS - Fail to Pay</EventType>
        <EventGroups>
            <EventGroup Word="DLSUSP">DL Suspension/Reinstatement</EventGroup>
            <EventGroup Word="PUBCASEV">Published Case Events</EventGroup>
        </EventGroups>
        <BaseEventType Code="C"/>
        <DocumentIndexNumber>1</DocumentIndexNumber>
        <ChargeID InternalChargeID="1616713723">10906059</ChargeID>
    </CaseEvent>
    <CaseEvent Date="05/12/2015" ID="160825565" InternalEventID="1721874622" xmlns:reslib="urn:reslib">
        <EventDate>05/12/2015</EventDate>
        <EventTime>7:36 AM</EventTime>
        <Docketable>True</Docketable>
        <IncludeOnTrans>True</IncludeOnTrans>
        <RecordingNeeded>false</RecordingNeeded>
        <TimestampCreate>05/12/2015 07:36:58:250</TimestampCreate>
        <Deleted>false</Deleted>
        <AgingClockActionKey Word="N">Does not affect aging clock</AgingClockActionKey>
        <EventType Word="DLREINSNON">DL reinstatement request to DPS Nonresident-Compact State</EventType>
        <EventGroups>
            <EventGroup Word="CASEMGMT">Case Management</EventGroup>
            <EventGroup Word="PUBCASEV">Published Case Events</EventGroup>
        </EventGroups>
        <BaseEventType Code="C"/>
        <DocumentIndexNumber>2</DocumentIndexNumber>
    </CaseEvent>

</Case>
<IntegrationConditions>
    <IntegrationCondition Word="DLNOTICDVS" Description="DL Notice to DVS">
        <NotificationEvent notificationType="DvsDlNotice" elementState="New" elementName="CaseEvent" elementKey="160825556" eventDate="05/11/2015" eventTime="3:42 PM" noticeTypeCode="SFTP">Suspension - Fail to Pay</NotificationEvent>
    </IntegrationCondition>
</IntegrationConditions>
</Integration>

My xsl code

    <?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
    <xsl:output method="xml" encoding="UTF-8" omit-xml-declaration="yes"/>
    <xsl:template match="/">
        <xsl:if test="((Integration/Case/SecurityGroup[not(contains(@Word,'SEAL'))]) or (not(Integration/CaseSecurityGroup))) and (/Integration/Case/CaseType[(@Word='CRM') or (@Word='VIB') or (@Word='DEL') or (@Word='D16') or (@Word='JPO') or (@Word='JTR')])">
            <xsl:apply-templates select="Integration/Case/CaseEvent[(@Op='A') and ((EventType/@Word='DLSUSPNON') or (EventType/@Word='DLSUSFTA') or (EventType/@Word='DLSUSFTP') or (EventType/@Word='DLREINSNON') or (EventType/@Word='DLREINSTAT') or (EventType/@Word='NPINDPS') or (EventType/@Word='DPSDVSCOR'))]"/>
        </xsl:if>
    </xsl:template>
    <xsl:template match="CaseEvent">
        <!-- check for Updated Events -->
        <xsl:choose>
            <xsl:when test="(EventType/@Word='DLSUSPNON') or (EventType/@Word='DLSUSFTA')">
                <NotificationEvent notificationType="DvsDlNotice">
                    <xsl:attribute name="elementState">New</xsl:attribute>
                    <xsl:attribute name="elementName">CaseEvent</xsl:attribute>
                    <xsl:attribute name="elementKey"><xsl:value-of select="@ID"/></xsl:attribute>
                    <xsl:attribute name="eventDate"><xsl:value-of select="EventDate"/></xsl:attribute>
                    <xsl:attribute name="eventTime"><xsl:value-of select="EventTime"/></xsl:attribute>
                    <xsl:attribute name="noticeTypeCode">SFTA</xsl:attribute>
                    <xsl:text>Suspension - Fail to Appear or Pay</xsl:text>
                </NotificationEvent>
            </xsl:when>
            <xsl:when test="(EventType/@Word='DLSUSFTP')">
                <NotificationEvent notificationType="DvsDlNotice">
                    <xsl:attribute name="elementState">New</xsl:attribute>
                    <xsl:attribute name="elementName">CaseEvent</xsl:attribute>
                    <xsl:attribute name="elementKey"><xsl:value-of select="@ID"/></xsl:attribute>
                    <xsl:attribute name="eventDate"><xsl:value-of select="EventDate"/></xsl:attribute>
                    <xsl:attribute name="eventTime"><xsl:value-of select="EventTime"/></xsl:attribute>
                    <xsl:attribute name="noticeTypeCode">SFTP</xsl:attribute>
                    <xsl:text>Suspension - Fail to Pay</xsl:text>
                </NotificationEvent>
            </xsl:when>
            <xsl:when test="(EventType/@Word='DLREINSNON') or (EventType/@Word='DLREINSTAT')">
                <NotificationEvent notificationType="DvsDlNotice">
                    <xsl:attribute name="elementState">New</xsl:attribute>
                    <xsl:attribute name="elementName">CaseEvent</xsl:attribute>
                    <xsl:attribute name="elementKey"><xsl:value-of select="@ID"/></xsl:attribute>
                    <xsl:attribute name="eventDate"><xsl:value-of select="EventDate"/></xsl:attribute>
                    <xsl:attribute name="eventTime"><xsl:value-of select="EventTime"/></xsl:attribute>
                    <xsl:attribute name="noticeTypeCode">REIN</xsl:attribute>
                    <xsl:text>Reinstatement - Fail to Appear or Pay</xsl:text>
                </NotificationEvent>
            </xsl:when>
            <xsl:when test="(EventType/@Word='NPINDPS')">
                <NotificationEvent notificationType="DvsDlNotice">
                    <xsl:attribute name="elementState">New</xsl:attribute>
                    <xsl:attribute name="elementName">CaseEvent</xsl:attribute>
                    <xsl:attribute name="elementKey"><xsl:value-of select="@ID"/></xsl:attribute>
                    <xsl:attribute name="eventDate"><xsl:value-of select="EventDate"/></xsl:attribute>
                    <xsl:attribute name="eventTime"><xsl:value-of select="EventTime"/></xsl:attribute>
                    <xsl:attribute name="noticeTypeCode">SNPI</xsl:attribute>
                    <xsl:text>No Proof of Insurance Notification</xsl:text>
                </NotificationEvent>
            </xsl:when>
            <xsl:when test="(EventType/@Word='DPSDVSCOR')">
                <!--Sort the dates in descending order to get the lastest date. Convert the date string first-->
                <xsl:for-each select="/Integration/Case/CaseEvent[(Deleted='false') and ((EventType/@Word='DLSUSPNON') or (EventType/@Word='DLSUSFTA') or (EventType/@Word='DLSUSFTP') or (EventType/@Word='DLREINSNON ') or (EventType/@Word='DLREINSTAT'))]">
                    <xsl:sort select="substring(EventDate,7,4)" order="descending"/>
                    <xsl:sort select="substring(EventDate,1,2)" order="descending"/>
                    <xsl:sort select="substring(EventDate,4,2)" order="descending"/>
                    <xsl:sort select="substring-after(EventTime,' ')" order="descending"/>
                    <xsl:sort select="substring-before(EventTime,':')" order="descending" data-type="number"/>
                    <xsl:sort select="substring-before(substring-after(EventTime,':'),' ')" order="descending" data-type="number"/>
                    <xsl:sort select="substring(TimestampCreate,7,4)" order="descending"/>
                    <xsl:sort select="substring(TimestampCreate,1,2)" order="descending"/>
                    <xsl:sort select="substring(TimestampCreate,4,2)" order="descending"/>
                    <xsl:sort select="substring(TimestampCreate,12,12)" order="descending"/>
                    <xsl:if test="position() = 1">
                        <xsl:choose>
                            <xsl:when test="(EventType/@Word='DLSUSPNON') or (EventType/@Word='DLSUSFTA') or (EventType/@Word='DLSUSFTP')">
                                <xsl:if test="count(/Integration/Case/CaseEvent[(EventType/@Word='NPINDPS') and (Deleted='false')])>0">
                                    <NotificationEvent notificationType="DvsDlNotice">
                                        <xsl:attribute name="elementState">New</xsl:attribute>
                                        <xsl:attribute name="elementName">CaseEvent</xsl:attribute>
                                        <xsl:attribute name="elementKey"><xsl:value-of select="@ID"/></xsl:attribute>
                                        <xsl:attribute name="eventDate"><xsl:value-of select="EventDate"/></xsl:attribute>
                                        <xsl:attribute name="eventTime"><xsl:value-of select="EventTime"/></xsl:attribute>
                                        <xsl:attribute name="noticeTypeCode">SNPI</xsl:attribute>
                                        <xsl:text>No Proof of Insurance Notification</xsl:text>
                                    </NotificationEvent>
                                </xsl:if>
                                <xsl:choose>
                                    <xsl:when test="(EventType/@Word='DLSUSPNON') or (EventType/@Word='DLSUSFTA')">
                                        <NotificationEvent notificationType="DvsDlNotice">
                                            <xsl:attribute name="elementState">New</xsl:attribute>
                                            <xsl:attribute name="elementName">CaseEvent</xsl:attribute>
                                            <xsl:attribute name="elementKey"><xsl:value-of select="@ID"/></xsl:attribute>
                                            <xsl:attribute name="eventDate"><xsl:value-of select="EventDate"/></xsl:attribute>
                                            <xsl:attribute name="eventTime"><xsl:value-of select="EventTime"/></xsl:attribute>
                                            <xsl:attribute name="noticeTypeCode">SFTA</xsl:attribute>
                                            <xsl:text>Suspension - Fail to Appear or Pay</xsl:text>
                                        </NotificationEvent>
                                    </xsl:when>
                                    <xsl:when test="(EventType/@Word='DLSUSFTP')">
                                        <NotificationEvent notificationType="DvsDlNotice">
                                            <xsl:attribute name="elementState">New</xsl:attribute>
                                            <xsl:attribute name="elementName">CaseEvent</xsl:attribute>
                                            <xsl:attribute name="elementKey"><xsl:value-of select="@ID"/></xsl:attribute>
                                            <xsl:attribute name="eventDate"><xsl:value-of select="EventDate"/></xsl:attribute>
                                            <xsl:attribute name="eventTime"><xsl:value-of select="EventTime"/></xsl:attribute>
                                            <xsl:attribute name="noticeTypeCode">SFTP</xsl:attribute>
                                            <xsl:text>Suspension - Fail to Pay</xsl:text>
                                        </NotificationEvent>
                                    </xsl:when>
                                </xsl:choose>
                            </xsl:when>
                            <xsl:when test="(EventType/@Word='DLREINSNON') or (EventType/@Word='DLREINSTAT')">
                                <NotificationEvent notificationType="DvsDlNotice">
                                    <xsl:attribute name="elementState">New</xsl:attribute>
                                    <xsl:attribute name="elementName">CaseEvent</xsl:attribute>
                                    <xsl:attribute name="elementKey"><xsl:value-of select="@ID"/></xsl:attribute>
                                    <xsl:attribute name="eventDate"><xsl:value-of select="EventDate"/></xsl:attribute>
                                    <xsl:attribute name="eventTime"><xsl:value-of select="EventTime"/></xsl:attribute>
                                    <xsl:attribute name="noticeTypeCode">REIN</xsl:attribute>
                                    <xsl:text>Reinstatement - Fail to Appear or Pay</xsl:text>
                                </NotificationEvent>
                            </xsl:when>
                        </xsl:choose>
                    </xsl:if>
                </xsl:for-each>
            </xsl:when>
        </xsl:choose>
    </xsl:template>
</xsl:stylesheet>
Tim C
  • 70,053
  • 14
  • 74
  • 93
Angela
  • 69
  • 5
  • possible duplicate of [XSL Transform extracting min and max dates](http://stackoverflow.com/questions/15279274/xsl-transform-extracting-min-and-max-dates) – vesan Jun 15 '15 at 23:24
  • 2
    Look at this question: http://stackoverflow.com/questions/15279274/xsl-transform-extracting-min-and-max-dates. And please try to remove all unnecessary elements from your XML and XSLT, leaving only that which your question is concerned about. That will make it easier for us to help you. – vesan Jun 15 '15 at 23:25
  • vesan, all the elements in my xslt are required – Angela Jun 16 '15 at 18:44
  • They are required for your business case, I'm sure, but not for this problem. Your question could have been: "I have xml like this: `05/11/201505/12/2015`, how do I select the element with the latest date?" From what I understand, the rest of your XSLT is fine, it's just this part that's giving you trouble. For more info please see here: http://stackoverflow.com/help/mcve – vesan Jun 16 '15 at 23:19
  • I agree I could have asked the question I a better way (format). However Tim did provide code that worked for my case. I am learning how to ask questions in a better simpler way – Angela Jun 19 '15 at 19:35

0 Answers0