Re: [xsl] Sum of identical nodes

Subject: Re: [xsl] Sum of identical nodes
From: "Joris Gillis" <roac@xxxxxxxxxx>
Date: Wed, 20 Jul 2005 10:34:46 +0200
Hi,

Tempore 08:18:34, die 07/20/2005 AD, hinc in xsl-list@xxxxxxxxxxxxxxxxxxxxxx scripsit Alvin Ng <ngkwangming@xxxxxxxxx>:

Each file in File1 and File2 have few hundreds nodes of <moid></moid>
and <mt></mt>. My biggest hindrance is how to recursively sum up each
node from each nodeset.

if the element structures in File1 and File2 are always the same, you can use something very simple:


<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; version="1.0">
<xsl:output method="xml" indent="yes"/>


<xsl:param name="file1" select="/"/>
<xsl:param name="file2" select="document('file2.xml')"/>

<xsl:template match="/">
<xml>
	<xsl:apply-templates select="$file1/xml/*" mode="merge"/>
</xml>
</xsl:template>

<xsl:template match="mt" mode="merge">
	<xsl:variable name="pos" select="position()"/>
	<xsl:copy>
		<xsl:value-of select="sum(. | $file2/xml/*[$pos])"/>
	</xsl:copy>
</xsl:template>

<xsl:template match="moid" mode="merge">
	<xsl:copy-of select="."/>
</xsl:template>

</xsl:stylesheet>


regards, -- Joris Gillis (http://users.telenet.be/root-jg/me.html) "N N1N;N.N8N5N9N1 N:N1N9 ON? N;N,N4N9 ON,N=ON1 N2N3N1N/N=N?ON= N1OO ON,N=O "

Current Thread