XSLTファイルがあります
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:param name="vrtfDoc2">
</xsl:param>
<xsl:variable name="vDoc2" select="$vrtfDoc2/*"/>
File 1 TO File 2 MATCH
<xsl:template match="node()|@*" name="identity">
<xsl:param name="pDoc2"/>
<xsl:copy>
<xsl:apply-templates select="node()|@*">
<xsl:with-param name="pDoc2" select="$pDoc2"/>
</xsl:apply-templates>
</xsl:copy>
</xsl:template>
<xsl:template match="/">
<xsl:apply-templates select="Topic/SubTopic/*">
<xsl:with-param name="pDoc2" select="$vDoc2"/>
</xsl:apply-templates>
-----------------------
File 2 TO File 1 MATCH
<xsl:apply-templates select="$vDoc2">
<xsl:with-param name="pDoc2" select="/*"/>
</xsl:apply-templates>
</xsl:template>
<xsl:template match="Topic/SubTopic/*">
<xsl:param name="pDoc2"/>
<xsl:variable name="guid" select="../@Guid" />
<table border="1" style="width:100%">
<thead>
<td>Current Element</td>
<td>Left Guid</td>
<td>Left</td>
<td>Right</td>
<td>Right Guid</td>
<td>Diff Type</td>
</thead>
<xsl:if test="not(. = $pDoc2/*/*[name()=name(current())])">
<tr>
<td>
<xsl:value-of select="name()"/>
</td>
<td>
<xsl:value-of select="$guid"/>
</td>
<td>
<xsl:value-of select="."/>
</td>
<td>
<xsl:value-of select="$pDoc2/*/*[name()=name(current())]"/>
</td>
<td>
</td>
<td>Diff</td>
</tr>
</xsl:if>
<xsl:if test=". = $pDoc2/*/*[name()=name(current())]">
<tr>
<td>
<xsl:value-of select="name()" />
</td>
<td>
<xsl:value-of select="../@Guid"/>
</td>
<td>
<xsl:value-of select="."/>
</td>
<td>
<xsl:value-of select="$pDoc2/*/*[name()=name(current())]"/>
</td>
<td>
<xsl:value-of select="$pDoc2/*/*[name()=name(current())]"/>
</td>
<td>Same</td>
</tr>
</xsl:if>
</table>
</xsl:template>
</xsl:stylesheet>
本質的に、変換ファイルは左から右へ、次に右から左への等価性をチェックします。唯一の問題は、私のxmlファイルに次のようなスニペットがあることです
<SubTopic Guid="462AF46304694D4785EF3B7E642AD8A2">
<Description xmlns="http://www.authorit.com/xml/authorit" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">Modification History</Description>
<Text xmlns="http://www.authorit.com/xml/authorit" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<p id="4">Not Applicable</p>
</Text>
</SubTopic>
xsltは、要素に一致する違いを上から下に順番に示しますが、正しい要素に一致することを保証するものではありません。つまり<SubTopic Guid="462AF46304694D4785EF3B7E642AD8A2">
、左側の比較xmlから<SubTopic Guid="462AF46304694D4785EF3B7E642AD8A2">
右側の比較xmlに比較しています。
この線
<xsl:variable name="guid" select="../@Guid" />
左側のxmlファイルから親GUIDを取得します。これは正しいですが、次のバリアントを試しました。
<xsl:if test="not(. = $pDoc2/*/*[name()=name(current())][@Guid=$guid])">
しかし、そのプロセスは、「[@ Guid =$guid]」が存在しないかのように行われます。
つまり、xsltは正しい要素を比較する必要があり、tが必要です。
xsltスキルが低いことは知っていますが、明らかな何かが欠けていると確信しています。