xsl-list
[Top] [All Lists]

Re: Conditional merge of 2 XML files

2005-09-01 02:35:41
Hi,

Tempore 04:54:32, die 09/01/2005 AD, hinc in 
xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com scripsit Thomas Tarpin-Lyonnet 
<bartleby(_at_)t-bart(_dot_)net>:

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)
«There are only 10 types of people in this world. Those who understand binary, and 
those who don't»

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



<Prev in Thread] Current Thread [Next in Thread>