INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

How do I remove comma after the last variable value?

How do I remove comma after the last variable value?

How do I remove comma after the last variable value?

(OP)
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

CODE --> xml

<?xml version="1.0" encoding="UTF-8"?>
<NotificationEvent notificationType="CasePartyUpdates" activeSignedPoNumbers="1605923,1623," xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fn="http://www.w3.org/2005/xpath-functions" xmlns:mscef="courts.state.mn.us/extfun" xmlns:msxsl="urn:schemas-microsoft-com:xslt">CasePartyUpdate</NotificationEvent> 

Expected output should look like this

CODE --> xml

<NotificationEvent notificationType="CasePartyUpdates" activeSignedPoNumbers="1605923,1623" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fn="http://www.w3.org/2005/xpath-functions" xmlns:mscef="courts.state.mn.us/extfun" xmlns:msxsl="urn:schemas-microsoft-com:xslt">CasePartyUpdate</NotificationEvent> 

xml document

CODE --> 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 --> xslt

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="3.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fn="http://www.w3.org/2005/xpath-functions" 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> 

RE: How do I remove comma after the last variable value?

Go back to the example provide by atlopes in thread426-1770592: How to I check for all Protection orders based on condition?.

You have failed to use the xsl:if processing instruction:

CODE --> XSL

<xsl:if test="position() &gt; 1"><xsl:text>, </xsl:text></xsl:if> 
This uses the technique of supplying a trailing comma on the existing string during the output of the second and subsequent items in the list. Inside a for-each, the position() function returns the 1-relative number of the context node within all the nodes selected by the select attribute.

(atlopes probably typed &gt; in his example, but the HTML processing, combined with it being a code block, turned it into a > character.)

Tom Morrison
Hill Country Software

RE: How do I remove comma after the last variable value?

Yes, Tom, I did. I'll try to keep in mind to &amp; before gt;, next time.

Thanks!

António

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close