Subject: Re: [xsl] Conditional merge of 2 XML files From: "Joris Gillis" <roac@xxxxxxxxxx> Date: Mon, 05 Sep 2005 21:15:20 +0200 |
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.
<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>
regards, -- Joris Gillis (http://users.telenet.be/root-jg/me.html) B+Error, keyboard not foundb press F1 to continueB; , BIOS
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Conditional merge of 2 XM, Thomas Tarpin-Lyonne | Thread | Re: [xsl] Conditional merge of 2 XM, Thomas Tarpin-Lyonne |
Re: [xsl] xslt2 complex content seq, David Carlisle | Date | Re: [xsl] muliple level sorting usi, Dimitre Novatchev |
Month |