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

How can i compare tags in two xml files

Subject: How can i compare tags in two xml files
From: "Sudhakar Bijjam" <sbijjam@xxxxxxxxxxxxxxxxxxx>
Date: Fri, 14 Jun 2002 16:30:33 +0530
compare tags
Hi,
I want to compare tags of two xml files and if it matches needs to display
the label name of the tag selected from second xml file in HTML form.

My xml files are:
XMLTemplate file1:

<xml>
    <order>
        <purchase>
            <pon>783</pon>
        </purchase>
    </order>
    <sales>
          <sod1>-----</sod1>
          <sod2>-----</sod2 >
          <pon>86578</pon>
     </sales>
</xml>

XMLTemplate file2:

<xml>
    <order     label = "order">
          <purchase     label= "purchase/>
               <pon     label = "pon"/>
        </purchase>
    </order>
     <sales     label = "sales">
           <sod1     label = "sod1"/
            <sod2     label = "sod2"/
            <pon     label = "salespon"/>>
     </sales>
</xml>

I have written code like this:

<xsl:stylesheet version="1.0">
<!-- calling xmlTemplatefile2.xml in xmlTemplatefile1-->
 <xsl:variable name="template" select="document('xmlTemplatefile2.xml')"/>
<!--Template will match root node of xmlTemplatefile1-->
 <xsl:template match="/">
  <html>
       <title>Purchase Order Form</title>
       <body>
            <table align="center" border="1" width="100%" >
                <xsl:variable name="tagname" select="local-name()"/>
                <xsl:for-each select="$template">
                      <xsl:if test="descendant::*[local-name() = $tagname]">
                           <xsl:for-each select="descendant::*[local-name()
= $tagname]">
                                <xsl:if test="position() = 1">
                                    <!------displaying the label of the tag
in HTML------->
                                     <xsl:value-of select="@label"/>
                                </xsl:if>
                            </xsl:for-each>
                       </xsl:if>
                 </xsl:for-each>
             </table>
         </body>
   </html>
</xsl:template>
</xsl:stylesheet>
If i execute my code i am getting problem with repetitive tags like 'pon'.I
am getting wrong label name  for the 'pon' tag defined under 'sales'.

Is it possible to compare the tags like this way which i had defined below?

XMLTemplate1                                            XMLTemplate2

xml                              -                                xml
xml/order                     -                                xml/order
xml/order/purchase       -                                xml/order/purchase
xml/order/purchase/pon-
xml/order/purchase/pon

How would i get full path of the each tag in XMLTemplate1 and XMLTemplate2?

Thanks for any help on this,

Sudhakar



 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


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.