Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?xml version="1.0"?>
- <catalog>
- <cd>d</cd>
- <cd>e</cd>
- <cd>f</cd>
- <cd>c</cd>
- </catalog>
- <?xml version="1.0"?>
- <catalog>
- <cd>a</cd>
- <cd>b</cd>
- <cd>c</cd>
- </catalog>
- <?xml version="1.0"?>
- <catalog>
- <cd>a</cd>
- <cd>b</cd>
- </catalog>
- <xsl:stylesheet version="2.0"
- xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
- <xsl:output method="xml" version="1.0" encoding="utf-8" indent="yes"/>
- <xsl:key name="cd" match="cd" use="." />
- <xsl:template match="/catalog">
- <xsl:copy>
- <xsl:copy-of select="cd[not(key('cd', ., document('a.xml')))]"/>
- </xsl:copy>
- </xsl:template>
- </xsl:stylesheet>
- <?xml version="1.0" encoding="UTF-8"?>
- <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
- <xsl:param name="compareWith" select="'a.xml'"/>
- <xsl:template match="*">
- <xsl:copy>
- <xsl:apply-templates/>
- </xsl:copy>
- </xsl:template>
- <xsl:template match="cd">
- <xsl:if test="not(document($compareWith)//cd = .)">
- <xsl:copy>
- <xsl:apply-templates/>
- </xsl:copy>
- </xsl:if>
- </xsl:template>
- </xsl:stylesheet>
- <?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"
- >
- <xsl:output method="xml" version="1.0" encoding="utf-8" indent="yes"/>
- <xsl:variable name="file2" select="document('C:Users320003708Desktoptestbedworkingb.xml')" />
- <xsl:template match="*|@*" name="splitter">
- <xsl:param name="comparer"/>
- <xsl:variable name="tree" select="." />
- <xsl:for-each select="$comparer/.">
- <xsl:choose>
- <xsl:when test="name($tree) != name(.)">
- <xsl:variable name="orphan-test">
- <match>
- <xsl:for-each select="msxsl:node-set(.)/../*">
- <xsl:if test="name($tree) = name(.)">
- <not-orphaned/>
- </xsl:if>
- </xsl:for-each>
- </match>
- </xsl:variable>
- <xsl:if test="not(msxsl:node-set($orphan-test)//not-orphaned)">
- <xsl:element name="{name($tree)}">
- <xsl:copy-of select="msxsl:node-set($tree)/@*"/>
- </xsl:element>
- </xsl:if>
- </xsl:when>
- <xsl:when test="name($tree) = name(.)">
- <xsl:variable name="attribute-value-mismatch-count-diverge">
- <xsl:call-template name="attribute-value-mismatch">
- <xsl:with-param name="attributes1" select="$tree/@*"/>
- <xsl:with-param name="attributes2" select="./@*"/>
- </xsl:call-template>
- </xsl:variable>
- <xsl:if test="count(msxsl:node-set($attribute-value-mismatch-count-diverge)/attribute-match/attribute) = 0">
- <xsl:if test="*">
- <xsl:apply-templates select="$tree/*">
- <xsl:with-param name="comparer" select="*"></xsl:with-param>
- </xsl:apply-templates>
- </xsl:if>
- <xsl:if test="not(*)">
- <xsl:variable name="attribute-value-mismatch-count">
- <xsl:call-template name="attribute-value-mismatch">
- <xsl:with-param name="attributes1" select="$tree/@*"/>
- <xsl:with-param name="attributes2" select="./@*"/>
- </xsl:call-template>
- </xsl:variable>
- <xsl:if test="count(msxsl:node-set($attribute-value-mismatch-count)/attribute-match/attribute) > 0">
- <xsl:variable name="matchvalue" select="."></xsl:variable>
- <xsl:variable name="siblings-mismatch">
- <nodes>
- <xsl:for-each select="msxsl:node-set($tree)/preceding-sibling::*">
- <xsl:variable name="sib-attribute-value-mismatch-count">
- <xsl:call-template name="attribute-value-mismatch">
- <xsl:with-param name="attributes1" select="$matchvalue/@*"/>
- <xsl:with-param name="attributes2" select="./@*"/>
- </xsl:call-template>
- </xsl:variable>
- <xsl:if test="count(msxsl:node-set($sib-attribute-value-mismatch-count)/attribute-match/attribute) > 0">
- <mismatch></mismatch>
- </xsl:if>
- </xsl:for-each>
- <xsl:for-each select="msxsl:node-set($tree)/following-sibling::*">
- <xsl:variable name="sib-attribute-value-mismatch-count">
- <xsl:call-template name="attribute-value-mismatch">
- <xsl:with-param name="attributes1" select="$matchvalue/@*"/>
- <xsl:with-param name="attributes2" select="./@*"/>
- </xsl:call-template>
- </xsl:variable>
- <xsl:if test="count(msxsl:node-set($sib-attribute-value-mismatch-count)/attribute-match/attribute) > 0">
- <mismatch></mismatch>
- </xsl:if>
- </xsl:for-each>
- </nodes>
- </xsl:variable>
- <xsl:if test="(count(msxsl:node-set($tree)/following-sibling::*) + count(msxsl:node-set($tree)/preceding-sibling::*)) = count(msxsl:node-set($siblings-mismatch)//mismatch)">
- <xsl:copy>
- <xsl:copy-of select="@*"/>
- </xsl:copy>
- </xsl:if>
- </xsl:if>
- </xsl:if>
- <xsl:if test="*">
- <xsl:if test="name(.) = name($tree)">
- <xsl:variable name="attribute-value-mismatch-count">
- <xsl:call-template name="attribute-value-mismatch">
- <xsl:with-param name="attributes1" select="$tree/@*"/>
- <xsl:with-param name="attributes2" select="./@*"/>
- </xsl:call-template>
- </xsl:variable>
- <xsl:if test="count(msxsl:node-set($attribute-value-mismatch-count)/attribute-match/attribute) > 0">
- <xsl:variable name="matchvalue" select="."></xsl:variable>
- <xsl:variable name="siblings-mismatch">
- <nodes>
- <xsl:for-each select="msxsl:node-set($tree)/preceding-sibling::*">
- <xsl:variable name="sib-attribute-value-mismatch-count">
- <xsl:call-template name="attribute-value-mismatch">
- <xsl:with-param name="attributes1" select="$matchvalue/@*"/>
- <xsl:with-param name="attributes2" select="./@*"/>
- </xsl:call-template>
- </xsl:variable>
- <xsl:if test="count(msxsl:node-set($sib-attribute-value-mismatch-count)/attribute-match/attribute) > 0">
- <mismatch></mismatch>
- </xsl:if>
- </xsl:for-each>
- <xsl:for-each select="msxsl:node-set($tree)/following-sibling::*">
- <xsl:variable name="sib-attribute-value-mismatch-count">
- <xsl:call-template name="attribute-value-mismatch">
- <xsl:with-param name="attributes1" select="$matchvalue/@*"/>
- <xsl:with-param name="attributes2" select="./@*"/>
- </xsl:call-template>
- </xsl:variable>
- <xsl:if test="count(msxsl:node-set($sib-attribute-value-mismatch-count)/attribute-match/attribute) > 0">
- <mismatch></mismatch>
- </xsl:if>
- </xsl:for-each>
- </nodes>
- </xsl:variable>
- <xsl:if test="(count(msxsl:node-set($tree)/following-sibling::*) + count(msxsl:node-set($tree)/preceding-sibling::*)) = count(msxsl:node-set($siblings-mismatch)//mismatch)">
- <xsl:copy>
- <xsl:copy-of select="@*"/>
- </xsl:copy>
- </xsl:if>
- </xsl:if>
- </xsl:if>
- </xsl:if>
- </xsl:if>
- </xsl:when>
- </xsl:choose>
- </xsl:for-each>
- </xsl:template>
- <xsl:template match="/">
- <xsl:variable name="IDs2" select="$file2/." />
- <xsl:variable name="zen">
- <root>
- <xsl:apply-templates select="@*|node()">
- <xsl:with-param name="comparer" select="$IDs2/*"></xsl:with-param>
- </xsl:apply-templates>
- </root>
- </xsl:variable>
- <xsl:call-template name="remove-duplicates">
- <xsl:with-param name="zen" select="msxsl:node-set($zen)/root/*"></xsl:with-param>
- </xsl:call-template>
- </xsl:template>
- <xsl:template name="attribute-match">
- <xsl:param name="attributes1" />
- <xsl:param name="attributes2" />
- <attribute-match>
- <xsl:if test="not($attributes1 or $attributes2)">
- <attribute />
- </xsl:if>
- <xsl:for-each select="$attributes1/@*">
- <xsl:variable name="attribute1" select="."/>
- <xsl:for-each select="$attributes2/@*">
- <xsl:if test="name(.) = name($attributes2/.)">
- <attribute>
- <xsl:value-of select="." />
- </attribute>
- </xsl:if>
- </xsl:for-each>
- </xsl:for-each>
- </attribute-match>
- </xsl:template>
- <xsl:template name="attribute-value-mismatch">
- <xsl:param name="attributes1" />
- <xsl:param name="attributes2" />
- <attribute-match>
- <xsl:if test="(count($attributes1) != count($attributes2))">
- <attribute />
- </xsl:if>
- <xsl:for-each select="$attributes1">
- <xsl:variable name="attribute1" select="."/>
- <xsl:variable name="result">
- <attroot>
- <xsl:for-each select="$attributes2">
- <xsl:if test="name(.) = name($attributes1/.)">
- <xsl:if test="not(. = $attributes1/.)">
- <not-matched-name/>
- </xsl:if>
- </xsl:if>
- <xsl:if test="name(.) != name($attributes1/.)">
- <not-matched-name/>
- </xsl:if>
- </xsl:for-each>
- </attroot>
- </xsl:variable>
- <xsl:if test="count(msxsl:node-set($result)//not-matched-name) = count(msxsl:node-set($attributes2))">
- <attribute />
- </xsl:if>
- </xsl:for-each>
- </attribute-match>
- </xsl:template>
- <xsl:template name="remove-duplicates">
- <xsl:param name="zen"></xsl:param>
- <xsl:if test="$zen[1]/following-sibling::*">
- <xsl:variable name="zen2">
- <xsl:call-template name="remove-duplicates">
- <xsl:with-param name="zen" select="$zen[1]/following-sibling::*"/>
- </xsl:call-template>
- </xsl:variable>
- <root>
- <xsl:for-each select="msxsl:node-set($zen2)/root/*">
- <xsl:variable name="attribute-mismatch">
- <xsl:call-template name="attribute-value-mismatch">
- <xsl:with-param name="attributes1" select="msxsl:node-set(.)/@*"></xsl:with-param>
- <xsl:with-param name="attributes2" select="msxsl:node-set($zen[1])/@*"></xsl:with-param>
- </xsl:call-template>
- </xsl:variable>
- <xsl:if test="count(msxsl:node-set($attribute-mismatch)/attribute-match/attribute) > 0">
- <xsl:copy>
- <xsl:copy-of select="./@*" />
- </xsl:copy>
- </xsl:if>
- </xsl:for-each>
- <xsl:copy>
- <xsl:copy-of select="$zen[1]"/>
- </xsl:copy>
- </root>
- </xsl:if>
- <xsl:if test="not($zen[1]/following-sibling::*)">
- <root>
- <xsl:copy-of select="$zen[1]"/>
- </root>
- </xsl:if>
- </xsl:template>
- </xsl:stylesheet>
Add Comment
Please, Sign In to add comment