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

comparing two nodes

Subject: comparing two nodes
From: "Danny Gallagher" <dgallagher999@xxxxxxxxxxx>
Date: Wed, 22 Dec 2004 10:47:06 -0500
xsl compare two nodes
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[@id='1']/CHECK/AMT != CHECKENTRY[@id='2']/CHECK/AMOUNT">
<xsl:value-of select="CHECKENTRY[@id='1']/CHECK/AMOUNT"/>
<xsl:value-of select="CHECKENTRY[@id='2']/CHECK/AMOUNT"/>
</xsl:if>
<xsl:if test="CHECKENTRY[@id='1']/CHECK/ROUTING/NAME != CHECKENTRY[@id='2']/CHECK/ROUTING/NAME">
<xsl:value-of select="CHECKENTRY[@id='1']/CHECK/ROUTING/NAME"/>
<xsl:value-of select="CHECKENTRY[@id='2']/CHECK/ROUTING/NAME"/>
</xsl:if>
<xsl:if test="CHECKENTRY[@id='1']/CHECK/ROUTING/ADDRESS1 != CHECKENTRY[@id='2']/CHECK/ROUTING/ADDRESS1">
<xsl:value-of select="CHECKENTRY[@id='1']/CHECK/ROUTING/ADDRESS1"/>
<xsl:value-of select="CHECKENTRY[@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

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.