[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

comparing nodesets to each other

Subject: comparing nodesets to each other
From: "Kai Hackemesser" <kaha@xxxxxx>
Date: Mon, 11 Apr 2005 17:14:25 +0200 (MEST)
xsl when test compare
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

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.