Subject: [xsl] keys and Xpath From: Ahmad J Reeves <ahmad@xxxxxxxxxxxxxx> Date: Sun, 21 Apr 2002 12:50:38 +0100 |
Hi, With the same xml example below I have two stylesheets for the following:- 1)xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="text"/> <xsl:key name="kByID" match="DIRECT | LOCAL | GLOBAL | ADMIN" use="CHARACTER_ID"/> <xsl:variable name="vUniqueCharacters" select="LOG/*[generate-id() = generate-id(key('kByID', CHARACTER_ID )[1] ) ]"/> <xsl:variable name="NL" select="'
'"/> <xsl:template match="/"> <xsl:value-of select="concat('Number of Unique Characters',' ',count($vUniqueCharacters))"/> <xsl:value-of select="$NL"/> <xsl:value-of select="$NL"/> <xsl:for-each select="$vUniqueCharacters"> <xsl:if test="not(CHARACTER_ID[. = preceding::CHARACTER_ID])"> <xsl:value-of select="concat('STATUS ',CHARACTER_STATUS, ' ', count(key('kByID',CHARACTER_ID)), $NL )"/> </xsl:if> </xsl:for-each> </xsl:template> </xsl:stylesheet> Is supposed to produce a list of unique character statuses and how many occurences of them there are. With the xml test below I get: - Number of Unique Characters 4 STATUS 6 3 STATUS 4 1 STATUS 3 1 STATUS 1 1 Instead of Number of Unique Characters 4 STATUS 6 1 STATUS 4 1 STATUS 3 1 STATUS 1 1 As the <xsl:if test="not(CHARACTER_ID[. = preceding::CHARACTER_ID])"> path maybe at fault. 2)<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="text"/> <xsl:key name="kLoc" match="LOG/*[@MESSAGE[./TARGET_CHARACTER_LOCATION_ID != ../LOCATION_ID]]" use="@MESSAGE"/> <xsl:variable name="NL" select="'
'"/> <xsl:variable name="vNotSame" select="LOG/*[@MESSAGE and generate-id(.) = generate-id(key('kLoc', @MESSAGE )[1] ) ]"/> <xsl:variable name="vTotalSent" select="count(LOG/*/MESSAGE)"/> <xsl:variable name="vNumNotSame" select="count(key('kLoc', @MESSAGE))"/> <xsl:template match="/"> <xsl:text> The total number of messages sent was: </xsl:text> <xsl:value-of select="$vTotalSent"/> <xsl:value-of select="$NL"/> <xsl:text> The total number of messages sent to a different location was </xsl:text> <xsl:value-of select="($vNumNotSame)"/> <xsl:value-of select="$NL"/> <xsl:text> The total number of messages sent to the same location was </xsl:text> <xsl:value-of select="$vTotalSent - $vNumNotSame"/> <xsl:value-of select="$NL"/> </xsl:template> </xsl:stylesheet> Is supposed to give the total number of messages sent plus the number sent where the target_character_location_id is different from the location_id of each message and the same for each message. Output should be:- The total number of messages sent was: 6 The total number of messages sent to a different location was 5 The total number of messages sent to the same location was 1 But is The total number of messages sent was: 6 The total number of messages sent to a different location was 0 The total number of messages sent to the same location was 6 I think my kLoc key is suspect? Thanks in Advance Ahmad 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> 24488 </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> <LOCAL> <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> 24485 </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> </LOCAL> <ADMIN> <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> </ADMIN> <GLOBAL> <COMMUNICATION_TYPE> PAGETELL </COMMUNICATION_TYPE> <Invoc_serial> 29 </Invoc_serial> <Serial> 19461913 </Serial> <USAGE> TELL </USAGE> <MESSAGE_TYPE> EMOTE </MESSAGE_TYPE> <CHARACTER_ID> 19910 </CHARACTER_ID> <CHARACTER_STATUS> 4 </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> </GLOBAL> <DIRECT> <COMMUNICATION_TYPE> PAGETELL </COMMUNICATION_TYPE> <Invoc_serial> 29 </Invoc_serial> <Serial> 19461994 </Serial> <USAGE> TELL </USAGE> <MESSAGE_TYPE> STD </MESSAGE_TYPE> <CHARACTER_ID> 88010 </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> 15444 </CHARACTER_ID> <CHARACTER_STATUS> 1 </CHARACTER_STATUS> <LOCATION_ID> 24488 </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> XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] ANN: ActiveState Visual XSLT , Eric Promislow | Thread | [xsl] javascript access to XML DOM , Steve Rosenberry |
Re: [xsl] Schema Exploration..., Mark R. Diggory | Date | Re: [xsl] Problem with API, Michael Welter |
Month |