[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

using keys for counting not sorting

Subject: using keys for counting not sorting
From: "Ahmad J. Reeves" <ahmad@xxxxxxxxxxxxxx>
Date: Sat, 29 Dec 2001 12:11:55 +0000
counting records in xsl
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


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.