I have a xml document which has 2 Service information elements. When I run my xsl , I only want to see one
Deleted notification
<NotificationEvent>
Deleted</NofiticationEvent> instead of two.
Here is the result with two NotificationEvents.
Code:
<?xml version="1.0" encoding="UTF-8"?>
<NotificationEvent xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fn="http://www.w3.org/2005/xpath-functions" notificationType="ProtectionOrderService" elementKey="1200" servedByWord="KL0820700" servedByText="Grove Police Department" dateServed="03/25/2014" timeServed="10:00 AM" howServedWord="PERSON" howServedText="In-Person" whoWasServedInternalId="704607705">Deleted</NotificationEvent>
<NotificationEvent xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fn="http://www.w3.org/2005/xpath-functions" notificationType="ProtectionOrderService" elementKey="1200" servedByWord="GN0170000" servedByText="County Sheriff's Office" dateServed="03/24/2014" timeServed="8:00 PM" howServedWord="SHORTFORM" howServedText="Short Form" whoWasServedInternalId="704607705">Deleted</NotificationEvent>
XSL should check if the <ServiceInfo> element has an Op="A" or "E" or "D". If it finds one or more of these, the output should be only one message. In my case I am getting two messages because there are two elements with <ServiceInfo Op="D">
Here is my xml
Code:
<ServicesInfo>
<ServiceInfo Op="D"> <ServedBy Op="D" Word="KL0820700">Grove Police Department</ServedBy>
<DateServed Op="D">03/25/2014</DateServed>
<TimeServed Op="D">10:00 AM</TimeServed>
<HowServed Op="D" Word="PERSON">In-Person</HowServed>
<WhoWasServed Op="D" InternalPartyID="704607705"/>
</ServiceInfo>
<ServiceInfo Op="D">
<ServedBy Op="D" Word="GN0170000">County Sheriff's Office</ServedBy>
<DateServed Op="D">03/24/2014</DateServed>
<TimeServed Op="D">8:00 PM</TimeServed>
<HowServed Op="D" Word="SHORTFORM">Short Form</HowServed>
<WhoWasServed Op="D" InternalPartyID="704607705"/>
</ServiceInfo>
</ServicesInfo>
Here is my XSLT Selector. How do I change the <xsl:for-each select
Code:
<xsl:template name="ProtectionOrderService">
<xsl:if test="Integration/ControlPoint='SAVE-PROTECTION-ORDER'">
<!-- Check for Added -->
<xsl:if test="Integration/Case/CaseType/@Word='DMA'">
<xsl:if test="Integration/ControlPoint/@UserID!='IntegrationAdmin'">
<xsl:for-each select="Integration/Case/ProtectionOrders/ProtectionOrder[(@Op='E') and ((Statuses/Status[(Current='true') and (not(@Op))]/Type/@Word='SIGNJUDCOR') or (Statuses/Status[(Current='true') and (not(@Op))]/Type/@Word='SIGNJUDOFC'))]/KLProtectionOrderAdditional/ServicesInfo/ServiceInfo[(@Op='A') or (@Op='E') or (@Op='D')]">
<NotificationEvent notificationType="ProtectionOrderService">
<xsl:attribute name="elementKey"><xsl:value-of select="../../@InternalProtectionOrderID"/></xsl:attribute>
<xsl:attribute name="elementKey"><xsl:value-of select="../../../@InternalProtectionOrderID"/></xsl:attribute>
<xsl:attribute name="servedByWord"><xsl:value-of select="ServedBy/@Word"/></xsl:attribute>
<xsl:attribute name="servedByText"><xsl:value-of select="ServedBy"/></xsl:attribute>
<xsl:attribute name="dateServed"><xsl:value-of select="DateServed"/></xsl:attribute>
<xsl:attribute name="timeServed"><xsl:value-of select="TimeServed"/></xsl:attribute>
<xsl:attribute name="howServedWord"><xsl:value-of select="HowServed/@Word"/></xsl:attribute>
<xsl:attribute name="howServedText"><xsl:value-of select="HowServed"/></xsl:attribute>
<xsl:attribute name="whoWasServedInternalId"><xsl:value-of select="WhoWasServed/@InternalPartyID"/></xsl:attribute>
<xsl:choose>
<xsl:when test="@Op='A'">Added</xsl:when>
<xsl:when test="@Op='E'">Modified</xsl:when>
<xsl:when test="@Op='D'">Deleted</xsl:when>
</xsl:choose>
</NotificationEvent>
</xsl:for-each>
</xsl:if>
</xsl:if>
</xsl:if>
</xsl:template>
This is the part I need to change but I am not sure how. I think I need to add a
WHERE clause and check if there is "A" or "E" or "D". If one is found even if there are several of each ("A", "E", "D"), the out put should only be one message.
Code:
<xsl:for-each select="Integration/Case/ProtectionOrders/ProtectionOrder[(@Op='E') and ((Statuses/Status[(Current='true') and (not(@Op))]/Type/@Word='SIGNJUDCOR') or (Statuses/Status[(Current='true') and (not(@Op))]/Type/@Word='SIGNJUDOFC'))]/KLProtectionOrderAdditional/ServicesInfo/ServiceInfo[(@Op='A') or (@Op='E') or (@Op='D')]">