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 20:40:52 +0200
On Thu, 01 Sep 2005 11:35:41 +0200, Joris Gillis <roac@xxxxxxxxxx> wrote:

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)

After partial recovery of the breakdown (caused by whitespace text nodes), I've managed to produce a solution.


This stylesheet should match your requirements more closely:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; version="1.0">
<xsl:output method="xml" indent="yes"/>
<xsl:strip-space elements="*"/>


<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:apply-templates>
</xsl:template>

<xsl:template match="*" mode="merge">
<xsl:param name="test"/>
<xsl:param name="reference"/>
<xsl:variable name="n"><xsl:number/></xsl:variable>
<xsl:choose>
<xsl:when test="count(.|$reference)=count($reference)">
<xsl:copy>
<xsl:copy-of select="$test[name()=name(current())][.=current()]/@*"/>
<xsl:apply-templates mode="merge" select="*|text()|$test/*">
<xsl:with-param name="test" select="$test[name()=name(current())][number($n)]/*"/>
<xsl:with-param name="reference" select="*"/>
</xsl:apply-templates>
</xsl:copy>
</xsl:when>
<xsl:when test="$reference and $test[count(.|current())=1]">
<xsl:if test="current()[text()[normalize-space()!='']][not(text()=$reference/text())]
or not($reference[name()=name(current())][number($n)])">
<xsl:copy-of select="."/>
</xsl:if>
</xsl:when>
</xsl:choose>
</xsl:template>


</xsl:stylesheet>


the input stays the same: <merge> <test>file_1.xml</test> <reference>file_2.xml</reference> </merge>


-- "NN= N?N/N4N1 O ON9 N?ON4N-N= N?N/N4N1" - N#O N:ON1ON7O

Current Thread