Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: [xsl] Conditional merge of 2 XML files

From: "Joris Gillis" <roac@---------->
To:
Date: 9/1/2005 9:35:00 AM
Hi,



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:



<merge>
	<test>file_1.xml</test>
	<reference>file_2.xml</reference>
</merge>

xsl:



<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 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:apply-templates>
</xsl:template>

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

<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()">
			<xsl:with-param name="test" select="$test/*"/>
			<xsl:with-param name="reference" select="$reference/*"/>
		</xsl:apply-templates>
	</xsl:copy>
	</xsl:when>
	<xsl:otherwise><xsl:copy-of select="."/></xsl:otherwise>
</xsl:choose>
</xsl:template>

</xsl:stylesheet>




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.



regards,
--
Joris Gillis (http://users.telenet.be/root-jg/me.html)
B+There are only 10 types of people in this world. Those who understand binary, and those who don'tB;


transparent
Print
Mail
Digg
delicious
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