Click here to Skip to main content
15,887,267 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
My first xml doc has ProtectionOrder that is not deleted. The output displayed by my xslt is correct.
The second xml doc has ProtectionOrder that have been deleted. The output displayed by my xslt is not working.

How do I make my xslt work for each of the two xml documents?

Expected output for ProtectionOrderStatus for ProtectionOrder that have not been deleted xml document This is working for me.

XML
<ext:ProtectionOrderStatus>
			<ext:ProtectionOrderStatusCode>SBJO</ext:ProtectionOrderStatusCode>
			<ext:ProtectionOrderStatusDate>2017-03-17</ext:ProtectionOrderStatusDate>
		</ext:ProtectionOrderStatus>


xml input document for a ProtectionOrder that is not deleted

XML
<Integration>
	<ControlPoint Timestamp="3/17/2017 10:20:59 AM">SAVE-PROTECTION-ORDER</ControlPoint>
	<ProtectionOrder Op="E">
		<Deleted>false</Deleted>
		<ProtectionOrderNumber>1700063</ProtectionOrderNumber>
		<Issued>03/17/2017</Issued>
		<Statuses>
			<Status Op="A">
				<Current>true</Current>
				<Active>Yes</Active>
				<Date Op="A">03/17/2017</Date>
				<Type Op="A" Word="SBJO">Signed By Judicial Officer</Type>
				<TimestampCreate Op="A">03/17/2017 10:20:59:350</TimestampCreate>
			</Status>
		</Statuses>
		<TimestampCreate>03/17/2017 10:20:28:403</TimestampCreate>
		<TimestampChange>03/17/2017 10:20:59:350</TimestampChange>
	</ProtectionOrder>
</Integration>

Expected output when a ProtectionOrder has been deleted
This is not working for me.
xml doc for ProtectionOrder that is deleted

XML
<ext:ProtectionOrderStatus>
    			<ext:ProtectionOrderStatusCode>DELETED</ext:ProtectionOrderStatusCode>
    			<ext:ProtectionOrderStatusDate>2017-03-17</ext:ProtectionOrderStatusDate>
    		</ext:ProtectionOrderStatus>


The following is my output which is wrong

XML
<ext:ProtectionOrderStatus>
    			<ext:ProtectionOrderStatusCode/>
    			<ext:ProtectionOrderStatusDate>2017-03-16</ext:ProtectionOrderStatusDate>
    		</ext:ProtectionOrderStatus>
    <ProtectionOrderStatus>SBJO<ProtectionOrderStatusDate>03/17/2017</ProtectionOrderStatusDate>
    </ProtectionOrderStatus>


xslt code

XML
<?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:mscef="courts.state.mn.us/extfun" xmlns:ext="http://www.courts.state.mn.us/ProtectionOrderExtension/1.0">
    <!--ext:ProtectionOrderStatus-->
    			<xsl:variable name="vCurrentTimestamp">
    				<xsl:choose>
    					<xsl:when test="count(/Integration/ControlPoint)>0">
    						<xsl:value-of select="mscef:formatDateTimeNumeric(string(/Integration/ControlPoint/@Timestamp))"/>
    					</xsl:when>
    					<xsl:otherwise>
    						<xsl:value-of select="mscef:currentDateTimeNumeric()"/>
    					</xsl:otherwise>
    				</xsl:choose>
    			</xsl:variable>
    			<xsl:variable name="vStatusDate" select="Statuses/Status[mscef:formatDateTimeNumeric(mscef:fixOdysseyTimestamp(string(TimestampCreate))) <=$vCurrentTimestamp][1]/Date"/>
    			<xsl:variable name="vStatusWord" select="Statuses/Status[mscef:formatDateTimeNumeric(mscef:fixOdysseyTimestamp(string(TimestampCreate))) <=$vCurrentTimestamp][1]/Type/@Word"/>
    			<ext:ProtectionOrderStatus>
    				<xsl:choose>
    					<xsl:when test="Deleted='true'">
    						<ext:ProtectionOrderStatusCode>DELETED</ext:ProtectionOrderStatusCode>
    					</xsl:when>
    				<xsl:otherwise>
    						<xsl:value-of select="$vStatusWord"/>
    					</xsl:otherwise>
    				</xsl:choose>
    				<ext:ProtectionOrderStatusDate>
    					<xsl:value-of select="mscef:formatDate(string($vStatusDate))"/>
    				</ext:ProtectionOrderStatusDate>
    			</ext:ProtectionOrderStatus>
    			
    	<msxsl:script language="JScript" implements-prefix="mscef"><![CDATA[
    		  function currentDateTime(){
       var oDate=new Date();
       return formatDateTime(oDate.toString());
      }
      function formatTime(sTime){
       if(sTime.length==0){
        return "";
       }
       else{
        var oDate=new Date(sTime);
        var str = oDate.getSeconds();
        return padZeroes(oDate.getHours().toString(),2) + ":"  +  padZeroes(oDate.getMinutes(),2) + ":" +  padZeroes(oDate.getSeconds(),2) + "-" + padZeroes(oDate.getTimezoneOffset() / 60,2) + ":00";     
       }
      }
      function formatDate(sDate){
       if(sDate.length==0){
        return "";
       }
       else{
        var oDate=new Date(sDate);
        var str = oDate.getSeconds();
        return oDate.getFullYear() + "-" +  padZeroes(oDate.getMonth() + 1,2) + "-" +  padZeroes(oDate.getDate(),2);     
       }
      }
      function formatDateTime(sDate){
       if(sDate.length==0){
        return "";
       }
       else{
        var oDate=new Date(sDate);
        var str = oDate.getSeconds();
        return oDate.getFullYear() + "-" +  padZeroes(oDate.getMonth() + 1,2) + "-" +  padZeroes(oDate.getDate(),2) + "T" + padZeroes(oDate.getHours().toString(),2) + ":"  +  padZeroes(oDate.getMinutes(),2) + ":" +  padZeroes(oDate.getSeconds(),2) + "-" + padZeroes(oDate.getTimezoneOffset() / 60,2) + ":00";     
       }
      }
    		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 currentDateTimeNumeric(){
    				var oDate=new Date();
    				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>


What I have tried:

XML
<?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:mscef="courts.state.mn.us/extfun" xmlns:ext="http://www.courts.state.mn.us/ProtectionOrderExtension/1.0">
    <!--ext:ProtectionOrderStatus-->
    			<xsl:variable name="vCurrentTimestamp">
    				<xsl:choose>
    					<xsl:when test="count(/Integration/ControlPoint)>0">
    						<xsl:value-of select="mscef:formatDateTimeNumeric(string(/Integration/ControlPoint/@Timestamp))"/>
    					</xsl:when>
    					<xsl:otherwise>
    						<xsl:value-of select="mscef:currentDateTimeNumeric()"/>
    					</xsl:otherwise>
    				</xsl:choose>
    			</xsl:variable>
    			<xsl:variable name="vStatusDate" select="Statuses/Status[mscef:formatDateTimeNumeric(mscef:fixOdysseyTimestamp(string(TimestampCreate))) <=$vCurrentTimestamp][1]/Date"/>
    			<xsl:variable name="vStatusWord" select="Statuses/Status[mscef:formatDateTimeNumeric(mscef:fixOdysseyTimestamp(string(TimestampCreate))) <=$vCurrentTimestamp][1]/Type/@Word"/>
    			<ext:ProtectionOrderStatus>
    				<xsl:choose>
    					<xsl:when test="Deleted='true'">
    						<ext:ProtectionOrderStatusCode>DELETED</ext:ProtectionOrderStatusCode>
    					</xsl:when>
    				<xsl:otherwise>
    						<xsl:value-of select="$vStatusWord"/>
    					</xsl:otherwise>
    				</xsl:choose>
    				<ext:ProtectionOrderStatusDate>
    					<xsl:value-of select="mscef:formatDate(string($vStatusDate))"/>
    				</ext:ProtectionOrderStatusDate>
    			</ext:ProtectionOrderStatus>
    			
    	<msxsl:script language="JScript" implements-prefix="mscef"><![CDATA[
    		  function currentDateTime(){
       var oDate=new Date();
       return formatDateTime(oDate.toString());
      }
      function formatTime(sTime){
       if(sTime.length==0){
        return "";
       }
       else{
        var oDate=new Date(sTime);
        var str = oDate.getSeconds();
        return padZeroes(oDate.getHours().toString(),2) + ":"  +  padZeroes(oDate.getMinutes(),2) + ":" +  padZeroes(oDate.getSeconds(),2) + "-" + padZeroes(oDate.getTimezoneOffset() / 60,2) + ":00";     
       }
      }
      function formatDate(sDate){
       if(sDate.length==0){
        return "";
       }
       else{
        var oDate=new Date(sDate);
        var str = oDate.getSeconds();
        return oDate.getFullYear() + "-" +  padZeroes(oDate.getMonth() + 1,2) + "-" +  padZeroes(oDate.getDate(),2);     
       }
      }
      function formatDateTime(sDate){
       if(sDate.length==0){
        return "";
       }
       else{
        var oDate=new Date(sDate);
        var str = oDate.getSeconds();
        return oDate.getFullYear() + "-" +  padZeroes(oDate.getMonth() + 1,2) + "-" +  padZeroes(oDate.getDate(),2) + "T" + padZeroes(oDate.getHours().toString(),2) + ":"  +  padZeroes(oDate.getMinutes(),2) + ":" +  padZeroes(oDate.getSeconds(),2) + "-" + padZeroes(oDate.getTimezoneOffset() / 60,2) + ":00";     
       }
      }
    		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 currentDateTimeNumeric(){
    				var oDate=new Date();
    				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>
Posted
Updated 20-Mar-17 8:47am
Comments
Afzaal Ahmad Zeeshan 20-Mar-17 14:26pm    
But, what exactly is being expected, and how is the result not expected?

1 solution

I showed what output should look like when a ProtectionOrder is deleted in the xml input document and also when the ProtectionOrder is not deleted in the xml input document.
My xslt code is working for ProtectionOrder that has not been deleted.
For the ProtectionOrder that is deleted, is it displaying an empty <ext:protectionorderstatuscode> element.
 
Share this answer
 
Comments
Member 11403304 21-Mar-17 7:40am    
When xml document does not have ProtectionOrder deleted as true I am not getting correct output.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900