Subject: [xsl] preceeding:sibling? From: Ahmad J Reeves <ahmad@xxxxxxxxxxxxxx> Date: Fri, 05 Apr 2002 14:21:23 +0100 |
Hi, For a sample of my xml below, I have written a stylesheet that lists all the unique rooms from the <LOCATION_ID> attribute and then lists all of the people from the <CHARACTER_ID> attribute that visited that room. As a person can sit in a room and send lots of messages I needed to remove any duplicate ID's until they left the room and came back in. So for example say ID number 3455 is in room 1111 and sends 6 messages and then moves to room 2222 and then comes back to 1111:- what actually happens = Room no:1111 3455 3455 3455 3455 3455 3455 3455 * he's come back here room no:2222 3455 What I actually need is Room no:1111 3455 * he comes in here but all future messages ignored until he leaves 4322 8976 4532 1324 3455 * he's come back here room no:2222 3455 ---------------------------------------------------------------- So I wrote this stylesheet to do the job:- <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="text" /> <xsl:key name="kByID" match="LOG/*" use="LOCATION_ID" /> <xsl:key name="kLocations" match="LOCATION_ID" use="." /> <xsl:variable name="vUniqueCharactersSending" select="LOG/*[generate-id() = generate-id(key('kByID', LOCATION_ID )[1] ) ]" /> <xsl:variable name="vRooms" select="LOG/*/LOCATION_ID [generate-id() = generate-id(key('kLocations', . )[1] ) ]" /> <xsl:variable name="NL" select="' '" /> <xsl:template match="/"> <xsl:value-of select="$NL" /> <xsl:for-each select="$vUniqueCharactersSending"> <xsl:value-of select="concat('Room', LOCATION_ID, ':', $NL )" /> <xsl:for-each select="/LOG/*/LOCATION_ID [. = current()/LOCATION_ID]"> <xsl:if test="not(../CHARACTER_ID = ../preceding-sibling::DIRECT [LOCATION_ID = current()][1]/CHARACTER_ID)"> <xsl:value-of select="concat(' ', ../CHARACTER_ID, $NL)" /> </xsl:if> </xsl:for-each> </xsl:for-each> </xsl:template> </xsl:stylesheet> ----------------------------------------------------------------------- but I'm still getting what actually happens instead of what I actually need. I can't see if my preceeding sibling test is deficient in any way. Any ideas gratefully received, Regards A. Sample xml: <LOG> <DIRECT> <COMMUNICATION_TYPE> PAGETELL </COMMUNICATION_TYPE> <Invoc_serial> 29 </Invoc_serial> <Serial> 19461910 </Serial> <USAGE> TELL </USAGE> <MESSAGE_TYPE> EMOTE </MESSAGE_TYPE> <CHARACTER_ID> 10010 </CHARACTER_ID> <CHARACTER_STATUS> 6 </CHARACTER_STATUS> <LOCATION_ID> 24488 </LOCATION_ID> <TARGET_CHARACTER_ID> 18735 </TARGET_CHARACTER_ID> <TARGET_CHARACTER_STATUS> 6 </TARGET_CHARACTER_STATUS> <TARGET_CHARACTER_LOCATION_ID> 10433 </TARGET_CHARACTER_LOCATION_ID> <MESSAGE> %#NF#%wthinks %y%l. o O ( %w%lThinks of a new prefix/suffix.%y%l ) </MESSAGE> <TIME> 'Tue, 01 Jan 2002 20:27:50 +0000' </TIME> </DIRECT> <DIRECT> <COMMUNICATION_TYPE> PAGETELL </COMMUNICATION_TYPE> <Invoc_serial> 29 </Invoc_serial> <Serial> 19461911 </Serial> <USAGE> TELL </USAGE> <MESSAGE_TYPE> EMOTE </MESSAGE_TYPE> <CHARACTER_ID> 10010 </CHARACTER_ID> <CHARACTER_STATUS> 6 </CHARACTER_STATUS> <LOCATION_ID> 24488 </LOCATION_ID> <TARGET_CHARACTER_ID> 23212 </TARGET_CHARACTER_ID> <TARGET_CHARACTER_STATUS> 3 </TARGET_CHARACTER_STATUS> <TARGET_CHARACTER_LOCATION_ID> 293 </TARGET_CHARACTER_LOCATION_ID> <MESSAGE> %#NF#%wthinks %y%l. o O ( %w%lThinks of a new prefix/suffix.%y%l ) </MESSAGE> <TIME> 'Tue, 01 Jan 2002 20:27:50 +0000' </TIME> </DIRECT> <DIRECT> <COMMUNICATION_TYPE> PAGETELL </COMMUNICATION_TYPE> <Invoc_serial> 29 </Invoc_serial> <Serial> 19461912 </Serial> <USAGE> TELL </USAGE> <MESSAGE_TYPE> EMOTE </MESSAGE_TYPE> <CHARACTER_ID> 10010 </CHARACTER_ID> <CHARACTER_STATUS> 6 </CHARACTER_STATUS> <LOCATION_ID> 24488 </LOCATION_ID> <TARGET_CHARACTER_ID> 16783 </TARGET_CHARACTER_ID> <TARGET_CHARACTER_STATUS> 5 </TARGET_CHARACTER_STATUS> <TARGET_CHARACTER_LOCATION_ID> 39784 </TARGET_CHARACTER_LOCATION_ID> <MESSAGE> %#NF#%wthinks %y%l. o O ( %w%lThinks of a new prefix/suffix.%y%l ) </MESSAGE> <TIME> 'Tue, 01 Jan 2002 20:27:50 +0000' </TIME> </DIRECT> <DIRECT> <COMMUNICATION_TYPE> PAGETELL </COMMUNICATION_TYPE> <Invoc_serial> 29 </Invoc_serial> <Serial> 19461913 </Serial> <USAGE> TELL </USAGE> <MESSAGE_TYPE> EMOTE </MESSAGE_TYPE> <CHARACTER_ID> 10010 </CHARACTER_ID> <CHARACTER_STATUS> 6 </CHARACTER_STATUS> <LOCATION_ID> 24488 </LOCATION_ID> <TARGET_CHARACTER_ID> 35257 </TARGET_CHARACTER_ID> <TARGET_CHARACTER_STATUS> 4 </TARGET_CHARACTER_STATUS> <TARGET_CHARACTER_LOCATION_ID> 293 </TARGET_CHARACTER_LOCATION_ID> <MESSAGE> %#NF#%wthinks %y%l. o O ( %w%lThinks of a new prefix/suffix.%y%l ) </MESSAGE> <TIME> 'Tue, 01 Jan 2002 20:27:50 +0000' </TIME> </DIRECT> <DIRECT> <COMMUNICATION_TYPE> PAGETELL </COMMUNICATION_TYPE> <Invoc_serial> 29 </Invoc_serial> <Serial> 19461994 </Serial> <USAGE> TELL </USAGE> <MESSAGE_TYPE> STD </MESSAGE_TYPE> <CHARACTER_ID> 20241 </CHARACTER_ID> <CHARACTER_STATUS> 3 </CHARACTER_STATUS> <LOCATION_ID> 31132 </LOCATION_ID> <TARGET_CHARACTER_ID> 14211 </TARGET_CHARACTER_ID> <TARGET_CHARACTER_STATUS> 5 </TARGET_CHARACTER_STATUS> <TARGET_CHARACTER_LOCATION_ID> 3726 </TARGET_CHARACTER_LOCATION_ID> <MESSAGE> "lol I found my own ways to amuse myself tho...like when liv tyler went 'ive got to take him to my father' im like yayaay were going to se steve tylerrrrr!!! " </MESSAGE> <TIME> 'Tue, 01 Jan 2002 20:28:08 +0000' </TIME> </DIRECT> <DIRECT> <COMMUNICATION_TYPE> PAGETELL </COMMUNICATION_TYPE> <Invoc_serial> 29 </Invoc_serial> <Serial> 19461995 </Serial> <USAGE> TELL </USAGE> <MESSAGE_TYPE> STD </MESSAGE_TYPE> <CHARACTER_ID> 20241 </CHARACTER_ID> <CHARACTER_STATUS> 3 </CHARACTER_STATUS> <LOCATION_ID> 31132 </LOCATION_ID> <TARGET_CHARACTER_ID> 12969 </TARGET_CHARACTER_ID> <TARGET_CHARACTER_STATUS> 3 </TARGET_CHARACTER_STATUS> <TARGET_CHARACTER_LOCATION_ID> 111 </TARGET_CHARACTER_LOCATION_ID> <MESSAGE> "lol I found my own ways to amuse myself tho...like when liv tyler went 'ive got to take him to my father' im like yayaay were going to se steve tylerrrrr!!! " </MESSAGE> <TIME> 'Tue, 01 Jan 2002 20:28:08 +0000' </TIME> </DIRECT> </LOG> Sample output( from much bigger file - just to show duplicates) Room 24488 : 10010 Room 31132 : 20241 Room 10433 : 18735 Room 39784 : 16783 27087 27087 27087 16783 16783 16783 16783 16783 16783 16783 16783 16783 16783 16783 16783 16783 16783 Room 293 : 35257 35257 35257 18735 23212 18735 23212 43442 44860 18908 20946 20946 18908 20946 18908 20946 20946 18908 20946 20946 18908 20946 18908 etc etc XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] selecting a subtree from , Laura Jenkins | Thread | Re: [xsl] preceeding:sibling?, J.Pietschmann |
[xsl] selecting a subtree from a tr, Joeri Belis | Date | [xsl] preceeding:sibling, Ahmad J Reeves |
Month |