Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with the use of key() 1

Status
Not open for further replies.

mcowen

Programmer
Joined
Oct 21, 2001
Messages
134
Location
GB
Hello,


This is similar to Dracosms post. In the following XML I want to group the MEMBER_NAME so that I only have 2 rows in a table with the totals for open, aborted etc...

Code:
<VFILE_DATA>
	<ALLOCATION_PERIOD>
		<CODE>157.00</CODE>
		<ALLOC_NAME>EM PSME (Purchase)</ALLOC_NAME>
		<MEMBER_NAME>PSM (Edgeware)</MEMBER_NAME>
		<MEMBER_CODE>14.00</MEMBER_CODE>
		<ALLOCATED>0.00</ALLOCATED>
		<OPEN>0</OPEN>
		<COMPLETED>0</COMPLETED>
		<ABORTED>0</ABORTED>
		<DECLINED>0</DECLINED>
	</ALLOCATION_PERIOD>
	<ALLOCATION_PERIOD>
		<CODE>158.00</CODE>
		<ALLOC_NAME>EM PSME (Remortgage)</ALLOC_NAME>
		<MEMBER_NAME>PSM (Edgeware)</MEMBER_NAME>
		<MEMBER_CODE>14.00</MEMBER_CODE>
		<ALLOCATED>0.00</ALLOCATED>
		<OPEN>0</OPEN>
		<COMPLETED>0</COMPLETED>
		<ABORTED>0</ABORTED>
		<DECLINED>0</DECLINED>
	</ALLOCATION_PERIOD>
	<ALLOCATION_PERIOD>
		<CODE>114</CODE>
		<ALLOC_NAME>Acme (Purchase)</ALLOC_NAME>
		<MEMBER_NAME>PSM (Wakefield)</MEMBER_NAME>
		<MEMBER_CODE>98</MEMBER_CODE>
		<ALLOCATED>12</ALLOCATED>
		<OPEN>0</OPEN>
		<COMPLETED>0</COMPLETED>
		<ABORTED>0</ABORTED>
		<DECLINED>0</DECLINED>
	</ALLOCATION_PERIOD>

So far I have tried this:

Code:
<xsl:key name="member-period" match="ALLOCATION_PERIOD/MEMBER_CODE" use="."/>

...more xsl
<xsl:for-each select="ALLOCATION_PERIOD/MEMBER_CODE[generate-id()=generate-id(key('member-period',.))]">

<tr> <xsl:attribute name="ID"><xsl:value-of select="CODE" /></xsl:attribute>
					              <td height="29" valign="top" ><a href="#" onclick="showButtons(this)"><xsl:value-of select="//MEMBER_NAME"/></a></td>
					              <td valign="top" class="tdtotals"><xsl:value-of select="sum(//OPEN)"/></td>
					              <td valign="top" class="tdtotals"><xsl:value-of select="sum(//ALLOCATED)"/></td>
					              <td valign="top" class="tdtotals"><xsl:value-of select="sum(//COMPLETED)"/></td>
					              <td valign="top" class="tdtotals"><xsl:value-of select="sum(//ABORTED)"/></td>
					              <td valign="top" class="tdtotals"><xsl:value-of select="sum(//DECLINED)"/></td>
					              <td valign="top" class="tdtotals"><xsl:value-of select="generate-id()"/></td>
</tr>
</xsl:for-each>

All I am getting is 2 PSM(Edgeware) rows with its total.

Any thoughts welcome.
Thanks
Matt

Matt
 
Try this:
Code:
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="[URL unfurl="true"]http://www.w3.org/1999/XSL/Transform">[/URL]
  <xsl:key name="member" match="MEMBER_CODE" use="."/> 
  <xsl:template match="/">
    <xsl:for-each select="//ALLOCATION_PERIOD[count(MEMBER_CODE | key('member', MEMBER_CODE)[1]) = 1]">
      <xsl:variable name="code" select = "MEMBER_CODE"/>
      <xsl:value-of select="MEMBER_NAME" />
      <xsl:value-of select="sum(//ALLOCATION_PERIOD[MEMBER_CODE=$code]/OPEN)" />
    </xsl:for-each>
  </xsl:template>
</xsl:stylesheet>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top