[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: XSLT Comparison of Two Trees
Doug Franklin wrote:
I wish to compare two (xml tree) documents, a previous document and it's Here is a stylesheet that outputs added, moved and deleted zip elements for each city element: <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"> <xsl:param name="pv" select="'previous.xml'"/> <xsl:variable name="pdoc" select="document($pv)"/> <xsl:variable name="cdoc" select="/"/> <xsl:output indent="yes"/> <xsl:template match="/"> <new-codes> <xsl:for-each select="cFieldOfficeList/city"> <city name="{@name}"> <xsl:copy-of select="zip[not(@zipCode = $pdoc/pFieldOfficeList/city/zip/@zipCode)]"/> </city> </xsl:for-each> </new-codes> <moved-codes> <xsl:for-each select="cFieldOfficeList/city"> <city name="{@name}"> <xsl:copy-of select="zip[not(@zipCode = 'zipTotals') and @zipCode = $pdoc/pFieldOfficeList/city[not(@name = current()/@name)]/zip/@zipCode]"/> </city> </xsl:for-each> </moved-codes> <deleted-codes> <xsl:for-each select="$pdoc/pFieldOfficeList/city"> <city name="{@name}"> <xsl:copy-of select="zip[not(@zipCode = $cdoc/cFieldOfficeList/city/zip/@zipCode)]"/> </city> </xsl:for-each> </deleted-codes> </xsl:template> </xsl:stylesheet> If applied against the posted XML input (current version) as the primary input document it outputs <new-codes> <city name="All areas"/> <city name="Total, California"/> <city name="Alhambra"> <zip zipCode="11111"><!-- This zip code was added to Alhambra --> <Total>1000</Total> </zip> </city> <city name="American River"/> <city name="Anaheim"/> <city name="Antioch"> <zip zipCode="22222"><!-- This zip code was added to Antioch --> <Total>5790</Total> </zip> </city> <city name="Auburn"> <zip zipCode="33333"><!-- This zip code was added to Auburn --> <Total>5790</Total> </zip> </city> <city name="Bakersfield"/> <city name="Bakersfield, East Hills"/> </new-codes> <moved-codes> <city name="All areas"/> <city name="Total, California"/> <city name="Alhambra"/> <city name="American River"/> <city name="Anaheim"> <zip zipCode="95610"><!-- zip code was moved from American River to Anaheim --> <Total>5750</Total> </zip> </city> <city name="Antioch"/> <city name="Auburn"> <zip zipCode="95628"><!-- This zip code was moved from American River to Auburn --> <Total>7325</Total> </zip> </city> <city name="Bakersfield"/> <city name="Bakersfield, East Hills"/> </moved-codes> <deleted-codes> <city name="All areas"/> <city name="Total, California"/> <city name="Alhambra"/> <city name="American River"> <zip zipCode="95621"> <Total>7135</Total> </zip> </city> <city name="Anaheim"/> <city name="Antioch"> <zip zipCode="94505"> <Total>1575</Total> </zip> </city> <city name="Auburn"/> <city name="Bakersfield"/> <city name="Bakersfield, East Hills"/> </deleted-codes> which I think is the correct list of nodes, based on the comments in the XML document. -- Martin Honnen http://msmvps.com/blogs/martin_honnen/
|
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
|