Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: [xsl] Conditional merge of 2 XML files

From: Thomas Tarpin-Lyonnet <bartleby@---------->
To:
Date: 9/2/2005 2:54:00 AM
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



*********************************
*     Thomas Tarpin-Lyonnet     *
* http://jaccal.sourceforge.net *
*********************************

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
<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


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent