This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
using keys for counting not sorting
- From: "Ahmad J. Reeves" <ahmad at dcs dot qmul dot ac dot uk>
- To: <xsl-list at lists dot mulberrytech dot com>
- Date: Sat, 29 Dec 2001 12:11:55 +0000
- Subject: [xsl] using keys for counting not sorting
- Reply-to: xsl-list at lists dot mulberrytech dot com
Hi,
I am trying to use keys (as I understand variables cannot change their value)
for counting rather than sorting:-
So with the following xml:
<LOG>
<DIRECT>
<COMMUNICATION_TYPE> PAGETELL </COMMUNICATION_TYPE>
<Invoc_serial> 27 </Invoc_serial>
<Serial> 3087908 </Serial>
<USAGE> TELL </USAGE>
<MESSAGE_TYPE> EMOTE </MESSAGE_TYPE>
<CHARACTER_ID> 10010 </CHARACTER_ID>
<CHARACTER_STATUS> 3 </CHARACTER_STATUS>
<LOCATION_ID> 45040 </LOCATION_ID>
<TARGET_CHARACTER_ID> 444444 </TARGET_CHARACTER_ID>
<TARGET_CHARACTER_STATUS> 6 </TARGET_CHARACTER_STATUS>
<TARGET_CHARACTER_LOCATION_ID> 23222 </TARGET_CHARACTER_LOCATION_ID>
<MESSAGE>hello</MESSAGE>
<TIME> 'Mon, 26 Nov 2001 15:40:29 +0000' </TIME>
</DIRECT>
etc etc 50,000 or so times
</LOG>
I need to count, then output as a number, the occurences of every CHARACTER_ID
(so I know they have sent a message) and also where that same ID occurs as
a TARGET_CHARACTER_ID (so I know they have received a message). So how
could I perhaps adapt Jennie's example
<xsl:key name="contacts-by-surname" match="contact" use="surname" />
<xsl:template match="records">
<xsl:for-each select="contact[count(. | key('contacts-by-surname',
surname)[1]) = 1]">
<xsl:sort select="surname" />
<xsl:value-of select="surname" />,<br />
<xsl:for-each select="key('contacts-by-surname', surname)">
<xsl:sort select="forename" />
<xsl:value-of select="forename" /> (<xsl:value-of select="title" />)<br />
</xsl:for-each>
</xsl:for-each>
</xsl:template>
to do this instead of sorting them, so the output looks like:-
CHARACTER_ID 3434343 sent 435 messages, received 234
CHARACTER_ID 121212 sent 432 messages, received 128
and also do a total sent and received and an average?
Cheers
Ahmad
-------------------------------------------------
Ahmad J Reeves BSc (Hons) MSc (Dist) PhD Student
Information, Media & Communication Research Group
Department of Computer Science
Queen Mary, University of London
E1 4NS
Tel +44(0) 207 882 5257
Fax +44(0) 208 980 6533
http://www.dcs.qmw.ac.uk/imc
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list