[xsl] combine node values

Subject: [xsl] combine node values
From: edwin colaco <Edwin.Colaco@xxxxxxx>
Date: Thu, 19 Sep 2002 13:22:42 -0400
My xml data file is as follows:
<AAA>
  <BBB>
    <CCC>
      <DDD acount=3 bcount=1 ccount=2>
	<EEE name="aaa">
      	   <FFF>
		<GGG id="1">
			<status>ok</>
		</GGG>

		<GGG id="2">
			<status>ok</>
		</GGG>

		<GGG id="3">
			<status>fail</>
		</GGG>
	
	  </FFF>
	</EEE>
	
	<EEE name="bbb">
	   <FFF>
		<GGG id="1">
			<status>ok</>
		</GGG>

		<GGG id="2">
			<status>fail</>
		</GGG>

		<GGG id="3">
			<status>ok</>
		</GGG>
	   </FFF>
	</EEE>
     </DDD>
   </CCC>

   <CCC>
     <DDD acount=3 bcount=1 ccount=2>
	<EEE name="aaa">
	   <FFF>
		<GGG id="1">
			<status>ok</>
		</GGG>
	
		<GGG id="2">
			<status>ok</>
		</GGG>

		<GGG id="3">
			<status>ok</>
		</GGG>
    	   </FFF>
	</EEE>
	<EEE name="bbb">
	    <FFF>
		<GGG id="1">
			<status>ok</>
		</GGG>
		<GGG id="2">
			<status>fail</>
		</GGG>

		<GGG id="3">
			<status>ok</>
		</GGG>
    	    </FFF>
	</EEE>
      </DDD>
   </CCC>
  </BBB>
</AAA>

The xsl stylesheet contains the following template rule:

<xsl:template name="Test">
   <P><B>Summary:</B></P>
	<table border="1" width="100%">
		<tr bgcolor="#666699">
			<th align="left"><font color="white">Col1</font></th>
			<th align="left"><font color="white">Col2</font></th>
			<th align="left"><font color="white">Col3</font></th>
		</tr>
		<xsl:for-each select="/AAA/BBB/CCC/DDD/EEE">
			<xsl:variable name="ct" select="count(FFF/GGG)"/>
			<xsl:variable name="okct" select="count(FFF/GGG[status='ok'])"/>

			<xsl:variable name="failct" select="count(FFF/GGG[status='fail'])"/>
			<xsl:variable name="successRate" select="((($ct)-($failct)) div ($ct))"/>
		<tr>
			<td><a href="#{@name}"><xsl:value-of select="@name"/></a></td>
			<td><xsl:value-of select="$ct"/></td><td><xsl:value-of select="$okct"/>
			</td><td><xsl:value-of select="$failct"/></td>
			<td><xsl:value-of select="format-number($successRate,'#00.00%')"/></td>
		</tr>
		</xsl:for-each>
	</table>
</xsl:template>

The result I get with this XSL template is 
Col1		Col2		Col3
aaa		2		1
bbb		2		1
aaa		3		0
bbb		2		1

I would like to get the following result instead
Col1		Col2		Col3
aaa		5		1
bbb		4		2

Would appreciate the help..Thanks

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread