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.


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="";

  <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="/">


    <!-- 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:template match="*">
      <!-- Sort the attributes by name. -->
      <xsl:for-each select="@*">
        <xsl:sort select="name( . )"/>

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


Hope this helps.

Best regards,


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

 XSL-List info and archive:

Current Thread