I would like to remove a comma after the last variable value in my output. I am not sure how to apply sub string.
Here is the output that I need to remove comma after last value. My output could have 1 to many values from the variable. If there is only one value, there should not be a comma after it. If there are 2 values, the comma should be removed after the 2nd value etc.
My output looks like this
Expected output should look like this
xml document
xslt code
Here is the output that I need to remove comma after last value. My output could have 1 to many values from the variable. If there is only one value, there should not be a comma after it. If there are 2 values, the comma should be removed after the 2nd value etc.
My output looks like this
XML:
<?xml version="1.0" encoding="UTF-8"?>
<NotificationEvent notificationType="CasePartyUpdates" activeSignedPoNumbers="1605923,1623," xmlns:xs="[URL unfurl="true"]http://www.w3.org/2001/XMLSchema"[/URL] xmlns:fn="[URL unfurl="true"]http://www.w3.org/2005/xpath-functions"[/URL] xmlns:mscef="courts.state.mn.us/extfun" xmlns:msxsl="urn:schemas-microsoft-com:xslt">CasePartyUpdate</NotificationEvent>
Expected output should look like this
XML:
<NotificationEvent notificationType="CasePartyUpdates" activeSignedPoNumbers="1605923,1623" xmlns:xs="[URL unfurl="true"]http://www.w3.org/2001/XMLSchema"[/URL] xmlns:fn="[URL unfurl="true"]http://www.w3.org/2005/xpath-functions"[/URL] xmlns:mscef="courts.state.mn.us/extfun" xmlns:msxsl="urn:schemas-microsoft-com:xslt">CasePartyUpdate</NotificationEvent>
xml document
XML:
<Integration xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns="">
<Case>
<CaseParty ID="18112817">
<ObservedRace Word="W">White</ObservedRace>
<ObservedEthnicity Word="NH">Non Hispanic</ObservedEthnicity>
<Connection Word="PET">
</Connection>
</CaseParty>
<CaseParty Op="E">
<ObservedRace Op="E" Word="M">Multiracial</ObservedRace>
<ObservedEthnicity Op="E" Word="R">Refused</ObservedEthnicity>
<Connection Word="RSP">
</Connection>
</CaseParty>
</Case>
<ProtectionOrder>
<ProtectionOrderNumber>1605921</ProtectionOrderNumber>
<Statuses>
<Status>
<Current>true</Current>
<Active>No</Active>
<Date>07/13/2016</Date>
<Type Word="SUPERSEDED">Superseded</Type>
<TimestampCreate>07/13/2016 13:09:18:567</TimestampCreate>
</Status>
</Statuses>
</ProtectionOrder>
<ProtectionOrder>
<ProtectionOrderNumber>1605923</ProtectionOrderNumber>
<Statuses>
<Status>
<Current>true</Current>
<Active>Yes</Active>
<Date>07/13/2016</Date>
<Type Word="SBJOCOR">Corrected - Signed By Judicial Officer</Type>
<TimestampCreate>07/13/2016 16:38:37:450</TimestampCreate>
</Status>
<Status>
<Current>false</Current>
<Active>Yes</Active>
<Date>07/13/2016</Date>
<Type Word="CORRECTING">Correcting</Type>
<TimestampCreate>07/13/2016 16:38:26:990</TimestampCreate>
</Status>
</Statuses>
</ProtectionOrder>
<ProtectionOrder>
<ProtectionOrderNumber>1623</ProtectionOrderNumber>
<Statuses>
<Status>
<Current>true</Current>
<Active>Yes</Active>
<Date>07/13/2016</Date>
<Type Word="SBJOCOR">Corrected - Signed By Judicial Officer</Type>
<TimestampCreate>07/13/2016 16:38:37:450</TimestampCreate>
</Status>
<Status>
<Current>false</Current>
<Active>Yes</Active>
<Date>07/13/2016</Date>
<Type Word="CORRECTING">Correcting</Type>
<TimestampCreate>07/13/2016 16:38:26:990</TimestampCreate>
</Status>
</Statuses>
</ProtectionOrder>
</Integration>
xslt code
Code:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="3.0" xmlns:xsl="[URL unfurl="true"]http://www.w3.org/1999/XSL/Transform"[/URL] xmlns:xs="[URL unfurl="true"]http://www.w3.org/2001/XMLSchema"[/URL] xmlns:fn="[URL unfurl="true"]http://www.w3.org/2005/xpath-functions"[/URL] xmlns:mscef="courts.state.mn.us/extfun" xmlns:msxsl="urn:schemas-microsoft-com:xslt">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="/">
<xsl:call-template name="CasePartyUpdates"/>
</xsl:template>
<!-- -->
<xsl:template name="CasePartyUpdates">
<xsl:if test="Integration/ControlPoint='SAVE-FAM-CASE'">
<xsl:if test="Integration/Case/CaseType/@Word='DMA'">
<xsl:variable name="vCurrentTimestamp" select="mscef:formatDateTimeNumeric(string(/Integration/ControlPoint/@Timestamp))"/>
<xsl:variable name="vActiveSignedPoNumbers1">
<xsl:for-each select="/Integration/ProtectionOrder">
<xsl:variable name="vCurrentPoStatus" select="Statuses/Status[mscef:formatDateTimeNumeric(mscef:fixOdysseyTimestamp(string(TimestampCreate))) <=$vCurrentTimestamp][1]/Type/@Word"/>
<xsl:if test="($vCurrentPoStatus='SBJO') or ($vCurrentPoStatus='SBJOCOR')">
<xsl:value-of select="ProtectionOrderNumber"/>
<xsl:text>,</xsl:text>
</xsl:if>
</xsl:for-each>
</xsl:variable>
<xsl:variable name="vActiveSignedPoNumbers2">
<xsl:value-of select="$vActiveSignedPoNumbers1"/>
</xsl:variable>
<!--Loop through each PO if current status is SBJO OR SBJOCOR add the PO number -->
<xsl:if test="(string-length($vActiveSignedPoNumbers2)>0)">
<xsl:for-each select="Integration/Case">
<xsl:choose>
<xsl:when test="(count(CaseParty[((ObservedRace/@Op='E') or (ObservedEthnicity/@Op='E')) and (Connection/@Word='RSP')] )>0)">
<NotificationEvent notificationType="CasePartyUpdates">
<xsl:attribute name="activeSignedPoNumbers">
<xsl:value-of select="$vActiveSignedPoNumbers2"/>
</xsl:attribute>
<xsl:text>CasePartyUpdate</xsl:text>
</NotificationEvent>
</xsl:when>
<xsl:when test="(count(CaseParty[CasePartyName/@Op='E']) >0)">
<NotificationEvent notificationType="CasePartyUpdates">
<xsl:attribute name="activeSignedPoNumbers">
<xsl:value-of select="$vActiveSignedPoNumbers2"/>
</xsl:attribute>
<xsl:text>CasePartyUpdate</xsl:text>
</NotificationEvent>
</xsl:when>
</xsl:choose>
</xsl:for-each>
</xsl:if>
</xsl:if>
</xsl:if>
</xsl:template>
<msxsl:script language="JScript" implements-prefix="mscef"><![CDATA[
function formatDateTimeNumeric(sDate){
if(sDate.length==0){
return "";
}
else{
var oDate=new Date(sDate);
var str = oDate.getSeconds();
return "" + oDate.getFullYear().toString() + padZeroes(oDate.getMonth() + 1,2) + padZeroes(oDate.getDate(),2) + padZeroes(oDate.getHours().toString(),2) + padZeroes(oDate.getMinutes(),2) + padZeroes(oDate.getSeconds(),2);
}
}
function fixOdysseyTimestamp(sDate){
/* Replace the ":" between seconds and miliseconds */
if(sDate.length==0){
return "";
}
else{
var strParts1 = sDate.split(" ");
var strTime = strParts1[1];
var strParts2 = strTime.split(":");
return strParts1[0] + " " + strParts2[0] + ":" + strParts2[1] + ":" + strParts2[2];
}
}
]]></msxsl:script>
</xsl:stylesheet>