Re: [xsl] Conditional merge of 2 XML files

Subject: Re: [xsl] Conditional merge of 2 XML files
From: Thomas Tarpin-Lyonnet <bartleby@xxxxxxxxxx>
Date: Fri, 02 Sep 2005 10:54:35 +0800
Thank you so much Joris, it's working so nice !!
I'm going to read it and try to understand it now.
Again, thank you ...


*     Thomas Tarpin-Lyonnet     *
* *

Quoting Joris Gillis <roac@xxxxxxxxxx>:

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

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="";
<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:template match="*" mode="merge">
<xsl:param name="test"/>
<xsl:param name="reference"/>
<xsl:variable name="n"><xsl:number/></xsl:variable>
	<xsl:when test="count(.|$reference)=count($reference)">
		<xsl:copy-of select="$test[name()=name(current())][.=current()]/@*"/>
		<xsl:apply-templates mode="merge" select="*|text()|$test/*">
			<xsl:with-param name="test"
			<xsl:with-param name="reference" select="*"/>
	<xsl:when test="$reference and $test[count(.|current())=1]">

		or not($reference[name()=name(current())][number($n)])">
			<xsl:copy-of select="."/>


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