[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Conditional merge of 2 XML files

Subject: Re: Conditional merge of 2 XML files
From: Thomas Tarpin-Lyonnet <bartleby@xxxxxxxxxx>
Date: Tue, 06 Sep 2005 09:03:42 +0800
merge select
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

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

Quoting Joris Gillis <roac@xxxxxxxxxx>:

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

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="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:choose>
				<xsl:when
test="self::testFamily|self::testNum|self::case|self::xcrdApi|self::api">
					<xsl:apply-templates mode="merge" select="*|text()|$test/*">
						<xsl:with-param name="test"
						select="$test[name()=name(current())][*[1]=current()/*[1]]/*"/>
						<xsl:with-param name="reference" select="*"/>
					</xsl:apply-templates>
				</xsl:when>
				<xsl:otherwise>
					<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:otherwise>
			</xsl:choose>
		</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>

regards,
--
Joris Gillis (http://users.telenet.be/root-jg/me.html)
B+Error, keyboard not foundb press F1 to continueB; , BIOS

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.