locked
How to compare 2 set of node; A not Exist in B; B not Exist in A RRS feed

  • Question

  • User-893002196 posted
    <xsl:template name="recurse">
        <xsl:param name="nodesA" />
        <xsl:param name="nodesB" />
    	<xsl:param name="countnodesA" />
        <xsl:param name="countnodesB" />
    	   
    	   <xsl:for-each select="$countnodesA">
    	   <xsl:if test="name=$nodesB/name">
    		   <xsl:value-of select="name"/>
    		   <xsl:call-template name="compare-names">
    			  <xsl:with-param name="a" select="value" />
    			  <xsl:with-param name="b" select="$nodesB/value" />
    		   </xsl:call-template>
    	   </xsl:if>
    	   <!--if node not exists in B--> <xsl:if test="not(name)"> <xsl:value-of select="name"/> <xsl:call-template name="compare-names"> <xsl:with-param name="a" select="value" /> <xsl:with-param name="b" select="value" /> <!-- how to set b value as "nill" --> </xsl:call-template> </xsl:if> <!--if node not exists in A--> <xsl:if test="not($nodesB/name)"> <xsl:value-of select="name"/> <xsl:call-template name="compare-names"> <xsl:with-param name="a" select="value" /> <!-- how to set a value as "nill" --> <xsl:with-param name="b" select="value" /> </xsl:call-template> </xsl:if>
    	   </xsl:for-each>
      </xsl:template>

    Please advise on the bold section with italic font:-   

     <!--if node not exists in B--> 	   <xsl:if test="not(name)">
    		   <xsl:value-of select="name"/>	
    		   <xsl:call-template name="compare-names">		
    			  <xsl:with-param name="a" select="value" />
    			  <xsl:with-param name="b" select="value" />  <!-- how to set b value as "nill" --> 		   </xsl:call-template>   	
    	   </xsl:if>
    	  <!--if node not exists in A--> 	   <xsl:if test="not($nodesB/name)">
    		   <xsl:value-of select="name"/>	
    		   <xsl:call-template name="compare-names">		
    			  <xsl:with-param name="a" select="value" /> <!-- how to set a value as "nill" --> 			  <xsl:with-param name="b" select="value" />  
    		   </xsl:call-template>   	
    	   </xsl:if>

    Please advise.

     

    Thank you.

     

    Regards,

    Micheale

    Thursday, April 4, 2013 12:13 AM

Answers

  • User-893002196 posted

    Solved!

     

    Here you go.

     

    <?xml version="1.0" encoding="utf-8"?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:exsl="http://exslt.org/common" xmlns:model="http://schemas.ad.by/model/2010" xmlns:html="http://www.w3.org/1999/xhtml" xmlns="http://www.w3.org/1999/xhtml" extension-element-prefixes="msxsl" exclude-result-prefixes="model html">
    <xsl:output method="xml" indent="yes" media-type="text/xml" encoding="utf-8" omit-xml-declaration="yes" />
    <xsl:strip-space elements="*" />
    <msxsl:script language="JScript" implements-prefix="exsl">this['node-set'] = function(x){ return x; }</msxsl:script>
    <xsl:param name="server-side-transformation" select="false()" /> 
    <xsl:param name="production-env" select="true()" /> 
    <xsl:param name="opera-mini" select="false()" /> 
    <xsl:param name="detect-xslt" select="false()" /> 
    
    
    
    <xsl:template match="/">
    	<xsl:variable name="docA" select="document(/files/file[1]/@href)" />
    	<xsl:variable name="docB" select="document(/files/file[2]/@href)" />
      
    		<xsl:variable name="sortedNodesA">
    			<xsl:for-each select="$docA/Items/Item//*">
    				  <xsl:sort select="name()" />
    				  <xsl:copy-of select="." />
    			</xsl:for-each>
    		</xsl:variable>
    
    		<xsl:variable name="sortedNodesB">
    			<xsl:for-each select="$docB/Items/Item//*">
    				  <xsl:sort select="name()" />
    				  <xsl:copy-of select="." />
    			</xsl:for-each>
    		</xsl:variable>
      
    		<xsl:variable name="rootnodesA" select="$docA/Items//*" />
    		<xsl:variable name="rootnodesB" select="$docB/Items//*" />
    
    
    		<xsl:call-template name="recurse">	
    		<xsl:with-param name="nodesA" select="exsl:node-set($sortedNodesA)" />
    		<xsl:with-param name="nodesB" select="exsl:node-set($sortedNodesB)" /> 
    		<xsl:with-param name="rootnodesA" select="exsl:node-set($rootnodesA)" />
    		<xsl:with-param name="rootnodesB" select="exsl:node-set($rootnodesB)" /> 		
    	</xsl:call-template>	
    </xsl:template>
      
    
    <xsl:template name="recurse">	
        <xsl:param name="nodesA" />
        <xsl:param name="nodesB" />	
    	<xsl:param name="rootnodesA" />
        <xsl:param name="rootnodesB" />
       
        <xsl:variable name="ListA">
    		<xsl:for-each select="$rootnodesA">
    		<xsl:value-of select="name" />
    		</xsl:for-each> 
    	</xsl:variable>
    	
    	<xsl:variable name="ListB"> <xsl:for-each select="$rootnodesB"> <xsl:value-of select="name" /> </xsl:for-each> </xsl:variable> <!--Id checking for status: Exist - NoChanges/Modified, Deleted and New Insert--> <xsl:for-each select="$rootnodesA"> <!--Exist in Both A & B--> <xsl:if test="name=$nodesB/name"> <xsl:call-template name="compare-names"> <xsl:with-param name="value_a" select="value" /> <xsl:with-param name="value_b" select="$nodesB/value" /> </xsl:call-template> </xsl:if> <!--Deleted--> <xsl:if test="name!=''"> <xsl:if test="not(contains($ListB,name))"> <xsl:call-template name="compare-names"> <xsl:with-param name="value_a" select="value" /> <xsl:with-param name="value_b" select="'nill'" /> </xsl:call-template> </xsl:if> </xsl:if> </xsl:for-each> <!--New Insert--> <xsl:for-each select="$rootnodesB"> <xsl:if test="name!=''"> <xsl:if test="not(contains($ListA,name))"> <xsl:call-template name="compare-names"> <xsl:with-param name="value_a" select="'nill'" /> <xsl:with-param name="value_b" select="value" /> </xsl:call-template> </xsl:if> </xsl:if> </xsl:for-each>  	
    </xsl:template>
    
    
    <xsl:template name="compare-names">
        <xsl:param name="value_a" />
        <xsl:param name="value_b" />	
    	<Opportunity>  
    	<OpportunityElement>	
    	<xsl:choose>
    		<!--<xsl:when test="$value_a=$value_b">[<xsl:value-of select="name"/> : <xsl:value-of select="name($value_a)"/>: <xsl:value-of select="$value_a"/>: <xsl:value-of select="$value_b"/> :  NoChanges]</xsl:when>-->		
    		<xsl:when test="$value_a!=$value_b and $value_b!='nill' and $value_a!='nill'"><referencenum><xsl:value-of select="name"/></referencenum><attribute><xsl:value-of select="name($value_a)"/></attribute><before><xsl:value-of select="$value_a"/></before><after><xsl:value-of select="$value_b"/></after><remark>Modified</remark></xsl:when>	
    		<xsl:when test="$value_a='nill'"><referencenum><xsl:value-of select="name"/></referencenum><attribute><xsl:value-of select="name($value_b)"/></attribute><before><xsl:value-of select="$value_a"/></before><after><xsl:value-of select="$value_b"/></after><remark>NewInserted</remark></xsl:when>
    		<xsl:when test="$value_b='nill'"><referencenum><xsl:value-of select="name"/></referencenum><attribute><xsl:value-of select="name($value_a)"/></attribute><before><xsl:value-of select="$value_a"/></before><after><xsl:value-of select="$value_b"/></after><remark>Deleted</remark></xsl:when>
        </xsl:choose>
    	</OpportunityElement>
    	</Opportunity>
    </xsl:template>
    
    </xsl:stylesheet>
    
    

    Regards,

    Micheale

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, April 4, 2013 4:01 AM

All replies

  • User-893002196 posted

    Solved!

     

    Here you go.

     

    <?xml version="1.0" encoding="utf-8"?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:exsl="http://exslt.org/common" xmlns:model="http://schemas.ad.by/model/2010" xmlns:html="http://www.w3.org/1999/xhtml" xmlns="http://www.w3.org/1999/xhtml" extension-element-prefixes="msxsl" exclude-result-prefixes="model html">
    <xsl:output method="xml" indent="yes" media-type="text/xml" encoding="utf-8" omit-xml-declaration="yes" />
    <xsl:strip-space elements="*" />
    <msxsl:script language="JScript" implements-prefix="exsl">this['node-set'] = function(x){ return x; }</msxsl:script>
    <xsl:param name="server-side-transformation" select="false()" /> 
    <xsl:param name="production-env" select="true()" /> 
    <xsl:param name="opera-mini" select="false()" /> 
    <xsl:param name="detect-xslt" select="false()" /> 
    
    
    
    <xsl:template match="/">
    	<xsl:variable name="docA" select="document(/files/file[1]/@href)" />
    	<xsl:variable name="docB" select="document(/files/file[2]/@href)" />
      
    		<xsl:variable name="sortedNodesA">
    			<xsl:for-each select="$docA/Items/Item//*">
    				  <xsl:sort select="name()" />
    				  <xsl:copy-of select="." />
    			</xsl:for-each>
    		</xsl:variable>
    
    		<xsl:variable name="sortedNodesB">
    			<xsl:for-each select="$docB/Items/Item//*">
    				  <xsl:sort select="name()" />
    				  <xsl:copy-of select="." />
    			</xsl:for-each>
    		</xsl:variable>
      
    		<xsl:variable name="rootnodesA" select="$docA/Items//*" />
    		<xsl:variable name="rootnodesB" select="$docB/Items//*" />
    
    
    		<xsl:call-template name="recurse">	
    		<xsl:with-param name="nodesA" select="exsl:node-set($sortedNodesA)" />
    		<xsl:with-param name="nodesB" select="exsl:node-set($sortedNodesB)" /> 
    		<xsl:with-param name="rootnodesA" select="exsl:node-set($rootnodesA)" />
    		<xsl:with-param name="rootnodesB" select="exsl:node-set($rootnodesB)" /> 		
    	</xsl:call-template>	
    </xsl:template>
      
    
    <xsl:template name="recurse">	
        <xsl:param name="nodesA" />
        <xsl:param name="nodesB" />	
    	<xsl:param name="rootnodesA" />
        <xsl:param name="rootnodesB" />
       
        <xsl:variable name="ListA">
    		<xsl:for-each select="$rootnodesA">
    		<xsl:value-of select="name" />
    		</xsl:for-each> 
    	</xsl:variable>
    	
    	<xsl:variable name="ListB"> <xsl:for-each select="$rootnodesB"> <xsl:value-of select="name" /> </xsl:for-each> </xsl:variable> <!--Id checking for status: Exist - NoChanges/Modified, Deleted and New Insert--> <xsl:for-each select="$rootnodesA"> <!--Exist in Both A & B--> <xsl:if test="name=$nodesB/name"> <xsl:call-template name="compare-names"> <xsl:with-param name="value_a" select="value" /> <xsl:with-param name="value_b" select="$nodesB/value" /> </xsl:call-template> </xsl:if> <!--Deleted--> <xsl:if test="name!=''"> <xsl:if test="not(contains($ListB,name))"> <xsl:call-template name="compare-names"> <xsl:with-param name="value_a" select="value" /> <xsl:with-param name="value_b" select="'nill'" /> </xsl:call-template> </xsl:if> </xsl:if> </xsl:for-each> <!--New Insert--> <xsl:for-each select="$rootnodesB"> <xsl:if test="name!=''"> <xsl:if test="not(contains($ListA,name))"> <xsl:call-template name="compare-names"> <xsl:with-param name="value_a" select="'nill'" /> <xsl:with-param name="value_b" select="value" /> </xsl:call-template> </xsl:if> </xsl:if> </xsl:for-each>  	
    </xsl:template>
    
    
    <xsl:template name="compare-names">
        <xsl:param name="value_a" />
        <xsl:param name="value_b" />	
    	<Opportunity>  
    	<OpportunityElement>	
    	<xsl:choose>
    		<!--<xsl:when test="$value_a=$value_b">[<xsl:value-of select="name"/> : <xsl:value-of select="name($value_a)"/>: <xsl:value-of select="$value_a"/>: <xsl:value-of select="$value_b"/> :  NoChanges]</xsl:when>-->		
    		<xsl:when test="$value_a!=$value_b and $value_b!='nill' and $value_a!='nill'"><referencenum><xsl:value-of select="name"/></referencenum><attribute><xsl:value-of select="name($value_a)"/></attribute><before><xsl:value-of select="$value_a"/></before><after><xsl:value-of select="$value_b"/></after><remark>Modified</remark></xsl:when>	
    		<xsl:when test="$value_a='nill'"><referencenum><xsl:value-of select="name"/></referencenum><attribute><xsl:value-of select="name($value_b)"/></attribute><before><xsl:value-of select="$value_a"/></before><after><xsl:value-of select="$value_b"/></after><remark>NewInserted</remark></xsl:when>
    		<xsl:when test="$value_b='nill'"><referencenum><xsl:value-of select="name"/></referencenum><attribute><xsl:value-of select="name($value_a)"/></attribute><before><xsl:value-of select="$value_a"/></before><after><xsl:value-of select="$value_b"/></after><remark>Deleted</remark></xsl:when>
        </xsl:choose>
    	</OpportunityElement>
    	</Opportunity>
    </xsl:template>
    
    </xsl:stylesheet>
    
    

    Regards,

    Micheale

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, April 4, 2013 4:01 AM
  • User260886948 posted

    Hi,

    I am very glad that you have solved your problem by yourself. It will help the others who meet the same issue as you.

    If you have any other problem, welcome to post it in the asp.net forums.

    Best Regards,
    Amy Peng 

    Friday, April 12, 2013 5:35 AM