Subject: [xsl] comparing nodesets to each other From: "Kai Hackemesser" <kaha@xxxxxx> Date: Mon, 11 Apr 2005 17:14:25 +0200 (MEST) |
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
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] substitute variable value, Michael Kay | Thread | Re: [xsl] comparing nodesets to eac, David Carlisle |
Re: [xsl] XSLT data fetching from m, David Carlisle | Date | Re: [xsl] Compatibility question, Emmanouil Batsis |
Month |