Subject: Re: Two file problem. From: Tobias.Grundmann@xxxxxxxxxxxxxxxxx (Tobias Grundmann) Date: Thu, 14 Sep 2000 14:21:34 +0200 |
Hi David, if the the two files are structural equivalent you could use a recursive process traversing both files or trees in parallel. See below for a script with searches differences between two files - well it stops when it encounters the first difference. This script could be extended to meet your needs I think. And BTW it doesn't need any extensions at all. Tobias <?xml version='1.0'?> <xsl:stylesheet xmlns:xsl='http://www.w3.org/1999/XSL/Transform' version='1.0'> <xsl:output method="xml" version="1.0" encoding="ISO-8859-1" indent="yes" /> <xsl:decimal-format name="en" decimal-separator='.'/> <!-- --> <xsl:strip-space elements="*"/> <xsl:preserve-space elements="xsl:text"/> <!-- ******************************************************************************** --> <xsl:param name="fileB" select="'docB.xml'"/> <xsl:template match="/"> <xsl:variable name="docB" select="document($fileB)"/> <xsl:message> FILE B: <xsl:value-of select="$fileB"/></xsl:message> <xsl:call-template name="diff"> <xsl:with-param name="nodeSetA" select="./*"/> <xsl:with-param name="nodeSetB" select="$docB/*"/> <xsl:with-param name="indent" select="''"/> </xsl:call-template> </xsl:template> <xsl:template name="diff"> <xsl:with-param name="nodeSetA"/> <xsl:with-param name="nodeSetB"/> <xsl:with-param name="indent"/> <xsl:if test="not(name($nodeSetA[position()=1]) = name($nodeSetB[position()=1]))"> <xsl:message terminate='yes'>Structural difference found!</xsl:message> </xsl:if> <xsl:if test="$nodeSetA"> <xsl:message>Comparing:<xsl:value-of select="$indent"/>A(<xsl:for-each select="$nodeSetA"><xsl:value-of select="name(.)"/><xsl:text> </xsl:text></xsl:for-each>) B(<xsl:value-of select="name($nodeSetB)"/>) </xsl:message> <xsl:call-template name="diff"> <!-- siblings --> <xsl:with-param name="nodeSetA" select="$nodeSetA[not (position()=1)]"/> <xsl:with-param name="nodeSetB" select="$nodeSetB[not (position()=1)]"/> <xsl:with-param name="indent" select="$indent"/> </xsl:call-template> <xsl:call-template name="diff"> <!-- childs --> <xsl:with-param name="nodeSetA" select="$nodeSetA[position()=1]/*"/> <xsl:with-param name="nodeSetB" select="$nodeSetB[position()=1]/*"/> <xsl:with-param name="indent" select="concat($indent,' ')"/> </xsl:call-template> </xsl:if> </xsl:template> </xsl:stylesheet> "Pawson, David" wrotes: > problem. > > Two xml files > > file 1 > <fa> > <a name="a1">3</a> > <a name="a2">5</a> > <a name="a3">2</a> > <a name="new">1</a> > </fa> > > file 2 > <fb> > <a name="a1">1</a> > > <a name="a3">1</a> > <a name="a4">2</a> > </fb> > > required output > <res> > <a name="a1">4</a> > <a name="a2">5</a> > <a name="a3">3</a> > <a name="a4">2</a> > <a name="new">1</a> > </res> > I.e. I want to sum the corresponding elements to the output file. > > Issues with my present solution. > Using a <for-each> on the input document I can add, to the output > using > processor:node-set(document(file-other.xml))/fx/a[@name=current()/@name] > the value of the corresponding element from the other file. > > If I use file 1 as the main document source, I can catch those > which match in file 2, but not those unique to file 2 (<a name="new"> > in the example.) > If I use file 2 as the main document source, I can get those > which match in file 1, but will miss those which are unique to file 1. > > Can anyone suggest a method of ensuring that I capture in the output > all the <a> elements from either file, without using more extensions > if possible. I think its the cup function, but no one has come up > with this as an extension even ... or have they? > > TIA DaveP > > XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: Two file problem., Eric van der Vlist | Thread | Re: Two file problem., Oliver Becker |
RE: for-each--stuck on very basic i, Eckenberger Axel | Date | RE: for-each--stuck on very basic i, Chris Bayes |
Month |