[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Simple XML Diff
Mark Anderson schrieb:
I'm trying to write an XML template that will compare two XML files that have *identical* structures.
What I need to do is compare every element an attribute in new.xml with the equivalent in master.xml [...] What I'm stuck with is [...] how to iterate through all elements and attributes in new.xml and find the equivalent in master.xml. Maybe this is a first step you can start working from: <?xml version="1.0" encoding="UTF-8"?> <xsl:transform version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="text"/> <xsl:variable name="master" select="document('master.xml')"/> <xsl:variable name="master-elms" select="$master//*"/> <xsl:template match="/"> <xsl:for-each select="//*"> <xsl:variable name="melm" select="$master-elms[ position() ]"/> <!-- Text --> <xsl:value-of select="concat( name(), ' : ')"/> <xsl:choose> <xsl:when test=". = $melm">=</xsl:when> <xsl:otherwise>!</xsl:otherwise> </xsl:choose> <xsl:text> </xsl:text> <!-- Attribute --> <xsl:for-each select="@*"> <xsl:sort select="name()"/> <xsl:value-of select="concat( '@', name(), ': ')"/> <xsl:variable name="name" select="name()"/> <xsl:choose> <xsl:when test=". = $melm/@*[ name() = $name ]">=</xsl:when> <xsl:otherwise>!</xsl:otherwise> </xsl:choose> <xsl:text> </xsl:text> </xsl:for-each> </xsl:for-each> </xsl:template> </xsl:transform> mludwig@forelle:~/Werkstatt/xsl > cat master.xml <Urmel u="U"> <eins>eins</eins> <zwei>zwei</zwei> <drei>drei</drei> <vier v="V">vier</vier> <x:fuenf xmlns:x="bla">fuenf</x:fuenf> </Urmel> mludwig@forelle:~/Werkstatt/xsl > cat A.xml <Urmel u="U"> <eins>eins</eins> <zwei>zwei</zwei> <drei>dreiunddrei_ig</drei> <vier v="W">vier</vier> <x:fuenf xmlns:x="bla">fuenf</x:fuenf> </Urmel> mludwig@forelle:~/Werkstatt/xsl > xsltproc Diff.xsl A.xml Urmel : ! @u: = eins : = zwei : = drei : ! vier : = @v: ! x:fuenf : = Michael Ludwig
|
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
|