RE: [xsl] XML diff

Subject: RE: [xsl] XML diff
From: "Robert C. Lyons" <boblyons@xxxxxxxxxx>
Date: Wed, 27 Jun 2001 12:20:26 -0400
Mike Tsirulnikov wrote:
> I wonder if anyone wrote or has seen a snippet of XSL that
> compares 2 XML files and finds out the differences of the 2.

Mike,

When I want to display the differences between two
XML files, I use SAXON and the following XSLT stylesheet to
normalize the two XML files; I then use the Unix diff command
to display the differences between the two normalized XML files.

<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
version="1.0">

  <xsl:output method="xml" indent="yes"/>

  <!-- Normalize the source document by doing the following:
       - Strip ignorable white space.
       - Sort attributes within each element by attribute name.
       - Indent the result tree.
  -->

  <xsl:strip-space elements="*"/>

  <xsl:template match="/">

    <xsl:apply-templates/>

    <!-- Add a linefeed at the end of the file, since
         SAXON doesn't do this automatically and since
         the Unix diff program complains when the last line
         in an input file is not delimited by a line terminator.
    -->
    <xsl:text>&#x0A;</xsl:text>

  </xsl:template>

  <xsl:template match="*">
    <xsl:copy>
      <!-- Sort the attributes by name. -->
      <xsl:for-each select="@*">
        <xsl:sort select="name( . )"/>
        <xsl:copy/>
      </xsl:for-each>
      <xsl:apply-templates/>
    </xsl:copy>
  </xsl:template>

  <xsl:template match="text()|comment()|processing-instruction()">
    <xsl:copy/>
  </xsl:template>

</xsl:stylesheet>

Hope this helps.

Best regards,

Bob

<sig name    = 'Bob Lyons'
     title   = 'B2B Integration Consultant'
     company = 'Unidex, Inc.'
     phone   = '+1-732-975-9877'
     email   = 'boblyons@xxxxxxxxxx'
     url     = 'http://www.unidex.com/'
     product = 'XML Convert: transforms flat files to XML and vice versa' />


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


Current Thread