xsl-list
[Top] [All Lists]

comparing two nodes

2004-12-22 08:47:06
I have everything working, but it seems there is probably an easier way to do it.

Here is my xml:

<?xml version="1.0" encoding="UTF-8"?>
<REPORT>
   <ENTRY>
       <CHECKENTRY id = '1'>
           <CHECK>
               <AMOUNT>10.00</AMOUNT>
               <ROUTING>
                   <NAME>Name</NAME>
                   <ADDRESS1>Address 1</ADDRESS1>
               </ROUTING>
           </CHECK>
       </CHECKENTRY>
       <CHECKENTRY id = '2'>
           <CHECK>
               <AMOUNT>9.00</AMOUNT>
               <ROUTING>
                   <NAME>Changed Name</NAME>
                   <ADDRESS1>Address 1</ADDRESS1>
               </ROUTING>
           </CHECK>
       </CHECKENTRY>
   </ENTRY>
</REPORT>

And the stylesheet:
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
   <xsl:output method="html"/>
  <xsl:template match="/REPORT">
           <xsl:for-each select="ENTRY">
<xsl:if test="CHECKENTRY[(_at_)id='1']/CHECK/AMT != CHECKENTRY[(_at_)id='2']/CHECK/AMOUNT"> <xsl:value-of select="CHECKENTRY[(_at_)id='1']/CHECK/AMOUNT"/> <xsl:value-of select="CHECKENTRY[(_at_)id='2']/CHECK/AMOUNT"/>
               </xsl:if>
<xsl:if test="CHECKENTRY[(_at_)id='1']/CHECK/ROUTING/NAME != CHECKENTRY[(_at_)id='2']/CHECK/ROUTING/NAME"> <xsl:value-of select="CHECKENTRY[(_at_)id='1']/CHECK/ROUTING/NAME"/> <xsl:value-of select="CHECKENTRY[(_at_)id='2']/CHECK/ROUTING/NAME"/>
               </xsl:if>
<xsl:if test="CHECKENTRY[(_at_)id='1']/CHECK/ROUTING/ADDRESS1 != CHECKENTRY[(_at_)id='2']/CHECK/ROUTING/ADDRESS1"> <xsl:value-of select="CHECKENTRY[(_at_)id='1']/CHECK/ROUTING/ADDRESS1"/> <xsl:value-of select="CHECKENTRY[(_at_)id='2']/CHECK/ROUTING/ADDRESS1"/>
               </xsl:if>
           </xsl:for-each>
  </xsl:template>
</xsl:stylesheet>

In the real world scenario, each <CHECK> will have many children (nested at different levels) that I need to compare values on.

Right now the stylesheet compares each tag and if they are not equal outputs the value.

Is there a way to not have to specify each element name and just run through all of them? I have control over both the stylesheet and xml.

Thanks for the help.

Danny Gallagher



--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



<Prev in Thread] Current Thread [Next in Thread>
  • comparing two nodes, Danny Gallagher <=