Reputation: 7463
I have an XSLT file
<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>
In essence the transform file checks equality left to right and then right to left. The only problem is my xml files have snippets similar to
<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>
The xslt gives me the differences matching elements by in order from top to bottom but doesn't guarantee that it matching the CORRECT element. That it, it is comparing <SubTopic Guid="462AF46304694D4785EF3B7E642AD8A2">
from the left comparison xml to <SubTopic Guid="462AF46304694D4785EF3B7E642AD8A2">
in the comparison right xml.
The line
<xsl:variable name="guid" select="../@Guid" />
gives me the parent guid from the left xml file, which is correct, but I've tried variants on the following
<xsl:if test="not(. = $pDoc2/*/*[name()=name(current())][@Guid=$guid])">
but that process as if the '[@Guid=$guid]' wasn't there.
In short the xslt must compare the correct elements and it must have t
I know my xslt skills are low but I am sure that I am missing something obvious.
Upvotes: 0
Views: 785
Reputation: 6105
I see that $guid
variable is built using the ../@Guid
(thus the parent
axes) and then the XPath expression is looking for an equality of names and guids but expect both to match on the same level. maybe it should be converted to [name() = name(current())][../@Guid = $guid]
? if this is not the case then maybe you can post a simplified version of your input and the expected result? this would help us help you debug the transform. also as a note, the . =
comparison will test for the equality of the string values of the two nodes. If you expect it to test for the existence of a node with the same name and parent Guid then you would need to shorten it to not($pDoc2/*/*[name()=name(current())][../@Guid=$guid]
Upvotes: 1