Re: [xsl] Conditional merge of 2 XML files

Subject: Re: [xsl] Conditional merge of 2 XML files
From: "Joris Gillis" <roac@xxxxxxxxxx>
Date: Thu, 01 Sep 2005 11:35:41 +0200

Tempore 04:54:32, die 09/01/2005 AD, hinc in xsl-list@xxxxxxxxxxxxxxxxxxxxxx scripsit Thomas Tarpin-Lyonnet <bartleby@xxxxxxxxxx>:

Where file_1.xml are the logs generated by a test campaign and file_2.xml are
the reference logs generated thanks to a test plan. The aim of doing
this is to
show all the tests that have been defined by the test plan but that we
forgot to
implement and then that don't appear in the logs.

I started working on a solution, but I'm getting stuck at this level (brain meltdown):

input XML:



<xsl:stylesheet xmlns:xsl=""; version="1.0">
<xsl:output method="xml" indent="yes"/>

<xsl:template match="merge">
	<xsl:variable name="test" select="document(test)"/>
	<xsl:variable name="reference" select="document(reference)"/>
	<xsl:apply-templates mode="merge" select="$reference/*">
		<xsl:with-param name="test" select="$test/*"/>
		<xsl:with-param name="reference" select="$reference/*"/>

<xsl:template match="*" mode="merge">
<xsl:param name="test"/>
<xsl:param name="reference"/>

	<xsl:when test="count(.|$reference)=count($reference)">
	<xsl:copy-of select="$test[name()=name(current())][.=current()]/@*"/>
		<xsl:apply-templates mode="merge" select="*|text()">
			<xsl:with-param name="test" select="$test/*"/>
			<xsl:with-param name="reference" select="$reference/*"/>
	<xsl:otherwise><xsl:copy-of select="."/></xsl:otherwise>


This will give correct result for your sample, but does not perform a real merge.

Some XPath pattern of the form "$test/*[not(text()=current()/../*/text())]" should be added to the the 'select' attribute of the last 'xsl:apply-templates'.

Maybe someone (hopefully myself, when my brain-meltdown is over) could build further on this.

Joris Gillis (
B+There are only 10 types of people in this world. Those who understand binary, and those who don'tB;

Current Thread