Guest User

Untitled

a guest
Mar 21st, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.73 KB | None | 0 0
  1. <?xml version="1.0"?>
  2. <catalog>
  3. <cd>d</cd>
  4. <cd>e</cd>
  5. <cd>f</cd>
  6. <cd>c</cd>
  7. </catalog>
  8.  
  9. <?xml version="1.0"?>
  10. <catalog>
  11. <cd>a</cd>
  12. <cd>b</cd>
  13. <cd>c</cd>
  14. </catalog>
  15.  
  16. <?xml version="1.0"?>
  17. <catalog>
  18. <cd>a</cd>
  19. <cd>b</cd>
  20. </catalog>
  21.  
  22. <xsl:stylesheet version="2.0"
  23. xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  24. <xsl:output method="xml" version="1.0" encoding="utf-8" indent="yes"/>
  25.  
  26. <xsl:key name="cd" match="cd" use="." />
  27.  
  28. <xsl:template match="/catalog">
  29. <xsl:copy>
  30. <xsl:copy-of select="cd[not(key('cd', ., document('a.xml')))]"/>
  31. </xsl:copy>
  32. </xsl:template>
  33.  
  34. </xsl:stylesheet>
  35.  
  36. <?xml version="1.0" encoding="UTF-8"?>
  37. <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
  38. <xsl:param name="compareWith" select="'a.xml'"/>
  39.  
  40. <xsl:template match="*">
  41. <xsl:copy>
  42. <xsl:apply-templates/>
  43. </xsl:copy>
  44. </xsl:template>
  45.  
  46. <xsl:template match="cd">
  47. <xsl:if test="not(document($compareWith)//cd = .)">
  48. <xsl:copy>
  49. <xsl:apply-templates/>
  50. </xsl:copy>
  51. </xsl:if>
  52. </xsl:template>
  53. </xsl:stylesheet>
  54.  
  55. <?xml version="1.0" encoding="utf-8"?>
  56.  
  57. <xsl:stylesheet version="1.0"
  58. xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  59. xmlns:msxsl="urn:schemas-microsoft-com:xslt"
  60. >
  61. <xsl:output method="xml" version="1.0" encoding="utf-8" indent="yes"/>
  62. <xsl:variable name="file2" select="document('C:Users320003708Desktoptestbedworkingb.xml')" />
  63. <xsl:template match="*|@*" name="splitter">
  64. <xsl:param name="comparer"/>
  65. <xsl:variable name="tree" select="." />
  66. <xsl:for-each select="$comparer/.">
  67. <xsl:choose>
  68. <xsl:when test="name($tree) != name(.)">
  69. <xsl:variable name="orphan-test">
  70. <match>
  71. <xsl:for-each select="msxsl:node-set(.)/../*">
  72. <xsl:if test="name($tree) = name(.)">
  73. <not-orphaned/>
  74. </xsl:if>
  75. </xsl:for-each>
  76. </match>
  77. </xsl:variable>
  78. <xsl:if test="not(msxsl:node-set($orphan-test)//not-orphaned)">
  79. <xsl:element name="{name($tree)}">
  80. <xsl:copy-of select="msxsl:node-set($tree)/@*"/>
  81. </xsl:element>
  82. </xsl:if>
  83. </xsl:when>
  84. <xsl:when test="name($tree) = name(.)">
  85. <xsl:variable name="attribute-value-mismatch-count-diverge">
  86. <xsl:call-template name="attribute-value-mismatch">
  87. <xsl:with-param name="attributes1" select="$tree/@*"/>
  88. <xsl:with-param name="attributes2" select="./@*"/>
  89. </xsl:call-template>
  90. </xsl:variable>
  91. <xsl:if test="count(msxsl:node-set($attribute-value-mismatch-count-diverge)/attribute-match/attribute) = 0">
  92. <xsl:if test="*">
  93. <xsl:apply-templates select="$tree/*">
  94. <xsl:with-param name="comparer" select="*"></xsl:with-param>
  95. </xsl:apply-templates>
  96. </xsl:if>
  97. <xsl:if test="not(*)">
  98. <xsl:variable name="attribute-value-mismatch-count">
  99. <xsl:call-template name="attribute-value-mismatch">
  100. <xsl:with-param name="attributes1" select="$tree/@*"/>
  101. <xsl:with-param name="attributes2" select="./@*"/>
  102. </xsl:call-template>
  103. </xsl:variable>
  104. <xsl:if test="count(msxsl:node-set($attribute-value-mismatch-count)/attribute-match/attribute) > 0">
  105. <xsl:variable name="matchvalue" select="."></xsl:variable>
  106. <xsl:variable name="siblings-mismatch">
  107. <nodes>
  108. <xsl:for-each select="msxsl:node-set($tree)/preceding-sibling::*">
  109. <xsl:variable name="sib-attribute-value-mismatch-count">
  110. <xsl:call-template name="attribute-value-mismatch">
  111. <xsl:with-param name="attributes1" select="$matchvalue/@*"/>
  112. <xsl:with-param name="attributes2" select="./@*"/>
  113. </xsl:call-template>
  114. </xsl:variable>
  115. <xsl:if test="count(msxsl:node-set($sib-attribute-value-mismatch-count)/attribute-match/attribute) > 0">
  116. <mismatch></mismatch>
  117. </xsl:if>
  118. </xsl:for-each>
  119. <xsl:for-each select="msxsl:node-set($tree)/following-sibling::*">
  120. <xsl:variable name="sib-attribute-value-mismatch-count">
  121. <xsl:call-template name="attribute-value-mismatch">
  122. <xsl:with-param name="attributes1" select="$matchvalue/@*"/>
  123. <xsl:with-param name="attributes2" select="./@*"/>
  124. </xsl:call-template>
  125. </xsl:variable>
  126. <xsl:if test="count(msxsl:node-set($sib-attribute-value-mismatch-count)/attribute-match/attribute) > 0">
  127. <mismatch></mismatch>
  128. </xsl:if>
  129. </xsl:for-each>
  130. </nodes>
  131. </xsl:variable>
  132. <xsl:if test="(count(msxsl:node-set($tree)/following-sibling::*) + count(msxsl:node-set($tree)/preceding-sibling::*)) = count(msxsl:node-set($siblings-mismatch)//mismatch)">
  133. <xsl:copy>
  134. <xsl:copy-of select="@*"/>
  135. </xsl:copy>
  136. </xsl:if>
  137. </xsl:if>
  138. </xsl:if>
  139. <xsl:if test="*">
  140. <xsl:if test="name(.) = name($tree)">
  141. <xsl:variable name="attribute-value-mismatch-count">
  142. <xsl:call-template name="attribute-value-mismatch">
  143. <xsl:with-param name="attributes1" select="$tree/@*"/>
  144. <xsl:with-param name="attributes2" select="./@*"/>
  145. </xsl:call-template>
  146. </xsl:variable>
  147. <xsl:if test="count(msxsl:node-set($attribute-value-mismatch-count)/attribute-match/attribute) > 0">
  148. <xsl:variable name="matchvalue" select="."></xsl:variable>
  149. <xsl:variable name="siblings-mismatch">
  150. <nodes>
  151. <xsl:for-each select="msxsl:node-set($tree)/preceding-sibling::*">
  152. <xsl:variable name="sib-attribute-value-mismatch-count">
  153. <xsl:call-template name="attribute-value-mismatch">
  154. <xsl:with-param name="attributes1" select="$matchvalue/@*"/>
  155. <xsl:with-param name="attributes2" select="./@*"/>
  156. </xsl:call-template>
  157. </xsl:variable>
  158. <xsl:if test="count(msxsl:node-set($sib-attribute-value-mismatch-count)/attribute-match/attribute) > 0">
  159. <mismatch></mismatch>
  160. </xsl:if>
  161. </xsl:for-each>
  162. <xsl:for-each select="msxsl:node-set($tree)/following-sibling::*">
  163. <xsl:variable name="sib-attribute-value-mismatch-count">
  164. <xsl:call-template name="attribute-value-mismatch">
  165. <xsl:with-param name="attributes1" select="$matchvalue/@*"/>
  166. <xsl:with-param name="attributes2" select="./@*"/>
  167. </xsl:call-template>
  168. </xsl:variable>
  169. <xsl:if test="count(msxsl:node-set($sib-attribute-value-mismatch-count)/attribute-match/attribute) > 0">
  170. <mismatch></mismatch>
  171. </xsl:if>
  172. </xsl:for-each>
  173. </nodes>
  174. </xsl:variable>
  175. <xsl:if test="(count(msxsl:node-set($tree)/following-sibling::*) + count(msxsl:node-set($tree)/preceding-sibling::*)) = count(msxsl:node-set($siblings-mismatch)//mismatch)">
  176. <xsl:copy>
  177. <xsl:copy-of select="@*"/>
  178. </xsl:copy>
  179. </xsl:if>
  180. </xsl:if>
  181. </xsl:if>
  182. </xsl:if>
  183. </xsl:if>
  184. </xsl:when>
  185. </xsl:choose>
  186. </xsl:for-each>
  187. </xsl:template>
  188. <xsl:template match="/">
  189. <xsl:variable name="IDs2" select="$file2/." />
  190. <xsl:variable name="zen">
  191. <root>
  192. <xsl:apply-templates select="@*|node()">
  193. <xsl:with-param name="comparer" select="$IDs2/*"></xsl:with-param>
  194. </xsl:apply-templates>
  195. </root>
  196. </xsl:variable>
  197. <xsl:call-template name="remove-duplicates">
  198. <xsl:with-param name="zen" select="msxsl:node-set($zen)/root/*"></xsl:with-param>
  199. </xsl:call-template>
  200. </xsl:template>
  201. <xsl:template name="attribute-match">
  202. <xsl:param name="attributes1" />
  203. <xsl:param name="attributes2" />
  204. <attribute-match>
  205. <xsl:if test="not($attributes1 or $attributes2)">
  206. <attribute />
  207. </xsl:if>
  208. <xsl:for-each select="$attributes1/@*">
  209. <xsl:variable name="attribute1" select="."/>
  210. <xsl:for-each select="$attributes2/@*">
  211. <xsl:if test="name(.) = name($attributes2/.)">
  212. <attribute>
  213. <xsl:value-of select="." />
  214. </attribute>
  215. </xsl:if>
  216. </xsl:for-each>
  217. </xsl:for-each>
  218. </attribute-match>
  219. </xsl:template>
  220. <xsl:template name="attribute-value-mismatch">
  221. <xsl:param name="attributes1" />
  222. <xsl:param name="attributes2" />
  223. <attribute-match>
  224. <xsl:if test="(count($attributes1) != count($attributes2))">
  225. <attribute />
  226. </xsl:if>
  227. <xsl:for-each select="$attributes1">
  228. <xsl:variable name="attribute1" select="."/>
  229. <xsl:variable name="result">
  230. <attroot>
  231. <xsl:for-each select="$attributes2">
  232. <xsl:if test="name(.) = name($attributes1/.)">
  233. <xsl:if test="not(. = $attributes1/.)">
  234. <not-matched-name/>
  235. </xsl:if>
  236. </xsl:if>
  237. <xsl:if test="name(.) != name($attributes1/.)">
  238. <not-matched-name/>
  239. </xsl:if>
  240. </xsl:for-each>
  241. </attroot>
  242. </xsl:variable>
  243. <xsl:if test="count(msxsl:node-set($result)//not-matched-name) = count(msxsl:node-set($attributes2))">
  244. <attribute />
  245. </xsl:if>
  246. </xsl:for-each>
  247. </attribute-match>
  248. </xsl:template>
  249. <xsl:template name="remove-duplicates">
  250. <xsl:param name="zen"></xsl:param>
  251. <xsl:if test="$zen[1]/following-sibling::*">
  252. <xsl:variable name="zen2">
  253. <xsl:call-template name="remove-duplicates">
  254. <xsl:with-param name="zen" select="$zen[1]/following-sibling::*"/>
  255. </xsl:call-template>
  256. </xsl:variable>
  257. <root>
  258. <xsl:for-each select="msxsl:node-set($zen2)/root/*">
  259. <xsl:variable name="attribute-mismatch">
  260. <xsl:call-template name="attribute-value-mismatch">
  261. <xsl:with-param name="attributes1" select="msxsl:node-set(.)/@*"></xsl:with-param>
  262. <xsl:with-param name="attributes2" select="msxsl:node-set($zen[1])/@*"></xsl:with-param>
  263. </xsl:call-template>
  264. </xsl:variable>
  265. <xsl:if test="count(msxsl:node-set($attribute-mismatch)/attribute-match/attribute) > 0">
  266. <xsl:copy>
  267. <xsl:copy-of select="./@*" />
  268. </xsl:copy>
  269. </xsl:if>
  270. </xsl:for-each>
  271. <xsl:copy>
  272. <xsl:copy-of select="$zen[1]"/>
  273. </xsl:copy>
  274. </root>
  275. </xsl:if>
  276. <xsl:if test="not($zen[1]/following-sibling::*)">
  277. <root>
  278. <xsl:copy-of select="$zen[1]"/>
  279. </root>
  280. </xsl:if>
  281. </xsl:template>
  282. </xsl:stylesheet>
Add Comment
Please, Sign In to add comment