Re: [xsl] Conditional merge of 2 XML files

Subject: Re: [xsl] Conditional merge of 2 XML files
From: Thomas Tarpin-Lyonnet <bartleby@xxxxxxxxxx>
Date: Tue, 06 Sep 2005 09:03:42 +0800
Thank you again Joris ... Even if you find that your solution is not that
generic, it is still working perfectly for what i intend to achieve ... Then
it's for me a very good solution. ;)
Then again thank you very much for your help, i appreciate.


*     Thomas Tarpin-Lyonnet     *
* *

Quoting Joris Gillis <roac@xxxxxxxxxx>:

Tempore 17:48:06, die 09/05/2005 AD, hinc in
xsl-list@xxxxxxxxxxxxxxxxxxxxxx scripsit Thomas Tarpin-Lyonnet

The solution that Joris gave me was working perfectly but
unfortunately, we have
changed a bit the structure of the xml and now there are some cases
where it's
not working.

The structure has become to complicated for me to be able to provide a generic solution.

I tweaked my original a bit with logic depending on element names
(this destroys its original generic allures). This adaption ensures
the correct output, but the stylesheet looks dirty now. Maybe other
posters on this lists can come up with infinitely cleaner (and easier
to understand) solutions. Also, if one fails to understand the logic
of the algorithm, then the fault lies most likely with me.

<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: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="."/>


Joris Gillis (
B+Error, keyboard not foundb press F1 to continueB; , BIOS

Current Thread