xsl-list
[Top] [All Lists]

Problem Counting number of Keys.

2004-09-22 05:21:04
Hi,
I am trying to create a 'Grouped' output from the following XSML/XSLT and I need to count the number of unique records in the group.

The output should look like:-

Contact               # of Visits      Account
----------------------------------------------------------
johnson, johnny        2             account 1 sub
bragg, billy               1              account2

Count = 2 <-----this is the value I am after, however when I try
<xsl:value-of select="count(key('keyContactGUID',//objectid.contactid))"/>
it returns 5.

What am I doing wrong???

Any help would be greatly appreciated.

Thanks,
Graham

XML engine:
Vendor: Microsoft
Vendor URL: http://www.microsoft.com


XML:

<resultset>
<result>
<activityid>{88320F75-4C77-4750-9E3F-C3991210941E}</activityid>
<ownerid name="Admin, Sys" dsc="0" type="8">{31157DA0-9F83-4495-B91A-A3EB012F84A3}</ownerid>
<owninguser>{31157DA0-9F83-4495-B91A-A3EB012F84A3}</owninguser>
<objectid.contactid>{BC2119B2-3BD6-4B86-8D3C-26738ABD63B5}</objectid.contactid>
<objectid.fullname>johnson, johnny</objectid.fullname>
<objectid.accountid name="account 1 sub" dsc="0">{FD5180B0-D7D8-45A4-8665-34A2807D2F3D}</objectid.accountid>
</result>
<result>
<activityid>{368CCF74-559C-450F-8DD4-23646DDB0787}</activityid>
<ownerid name="Admin, Sys" dsc="0" type="8">{31157DA0-9F83-4495-B91A-A3EB012F84A3}</ownerid>
<owninguser>{31157DA0-9F83-4495-B91A-A3EB012F84A3}</owninguser>
<objectid.contactid>{BC2119B2-3BD6-4B86-8D3C-26738ABD63B5}</objectid.contactid>
<objectid.fullname>johnson, johnny</objectid.fullname>
<objectid.accountid name="account 1 sub" dsc="0">{FD5180B0-D7D8-45A4-8665-34A2807D2F3D}</objectid.accountid>
</result>
<result>
<activityid>{368CCF74-559C-450F-8DD4-23646DDX0787}</activityid>
<ownerid name="Admin, Sys" dsc="0" type="8">{31157DA0-9F83-4495-B91A-A3EB012F84A3}</ownerid>
<owninguser>{31157DA0-9F83-4495-B91A-A3EB012F84A3}</owninguser>
<objectid.contactid>{4FC6C984-6890-424E-9A73-30A5BA083422}</objectid.contactid>
<objectid.fullname>bragg, billy</objectid.fullname>
<objectid.accountid name="account2" dsc="0">{FG5180B0-D7D8-45A4-8665-34A2807D2F3D}</objectid.accountid>
</result>
</resultset>



XSLT:

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
<!-- Define keys used to group elements -->
<xsl:key name="keyContactGUID" match="result" use="objectid.contactid"/>


<xsl:template match="/">
<!-- autonumber for the sorting id column -->
<html>
<body>
<h2>Grouping Test</h2>

<table border="1">
<tr bgcolor="#9acd32">
<th>Contact</th>
<th># of Visits</th>
<th>Account</th>
</tr>

<!-- Process each Contact-->
<xsl:for-each select="//result[generate-id(.) = generate-id(key('keyContactGUID',objectid.contactid)[1])]">

<tr>
<xsl:variable name="CID">
<xsl:value-of select="objectid.contactid"/>
</xsl:variable>
<td>
<xsl:value-of select="objectid.fullname"/>
<p/>
</td>
<td>
<xsl:value-of select="count(key('keyContactGUID',objectid.contactid)/activityid)"/>
</td>
<td>
<xsl:value-of select="objectid.accountid/@name"/>
</td>
</tr>

</xsl:for-each>


</table>

Count = <xsl:value-of select="count(key('keyContactGUID',resultset//result//objectid.contactid))"/>

</body>
</html>
</xsl:template>
</xsl:stylesheet>

_________________________________________________________________
On the road to retirement? Check out MSN Life Events for advice on how to get there! http://lifeevents.msn.com/category.aspx?cid=Retirement



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