[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] RE: XML diff
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>
</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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|