|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] comparing nodesets to each other
Hello,
I currently have to compare two nodelist to each other for differences.
I have in one XML file a structure 'before' and a structure 'after'. Let's
say a recipe and a variation of this recipe. I now need to pick out all
differences, for to mark them in my output report, like the diff command
does. If I found a difference I need to pick out some attributes and values
from this and it's child nodes.
this is my current [not working] idea:
<xsl:template name="recipe-compare">
<xsl:param name="pattern"/>
<xsl:param name="recipe"/>
<xsl:variable name="variation">
<xsl:for-each select="$pattern">
<xsl:variable name="current-findnumber"
select="./Attribute[@Name='FindNumber']/Value"/>
<xsl:variable name="compare-node">
<xsl:for-each select="$recipe">
<xsl:if test="./Attribute[@Name='FindNumber']/Value =
$current-findnumber">
<xsl:copy-of select="."/>
</xsl:if>
</xsl:for-each>
</xsl:variable>
<xsl:if test=". != $compare-node">
<xsl:copy-of select="."/>
<xsl:attribute name="different">current</xsl:attribute>
</xsl:if>
</xsl:for-each>
<xsl:for-each select="$recipe">
<xsl:variable name="current-findnumber"
select="./Attribute[@Name='FindNumber']/Value"/>
<xsl:variable name="compare-node">
<xsl:for-each select="$pattern">
<xsl:if test="./Attribute[@Name='FindNumber']/Value =
$current-findnumber">
<xsl:copy-of select="."/>
</xsl:if>
</xsl:for-each>
</xsl:variable>
<xsl:if test=". != $compare-node">
<xsl:copy-of select="."/>
<xsl:attribute name="different">pattern</xsl:attribute>
</xsl:if>
</xsl:for-each>
</xsl:variable>
<xsl:for-each select="$variation">
<xsl:sort select="./Attribute[@Name='FindNumber']/Value"/>
<fo:table-row>
<xsl:choose>
<xsl:when test="@different = 'current'">
<fo:table-cell><fo:block><xsl:value-of
select="./object/Attribute[@Name='PartNumber']/Value"/></fo:block></fo:table-cell>
<fo:table-cell><fo:block>100</fo:block></fo:table-cell>
<fo:table-cell></fo:table-cell>
</xsl:when>
<xsl:otherwise>
<fo:table-cell><fo:block><xsl:value-of
select="./object/Attribute[@Name='PartNumber']/Value"/></fo:block></fo:table-cell>
<fo:table-cell><fo:block>100</fo:block></fo:table-cell>
<fo:table-cell></fo:table-cell>
</xsl:otherwise>
</xsl:choose>
</fo:table-row>
</xsl:for-each>
</xsl:template>
Still learning... Any suggestion or correction highly appreciated...
Regards,
Kai
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|

Cart








