[XSL-LIST Mailing List Archive Home]
[By Thread]
[By Date]
[xsl] adding a condition to a stylesheet
Subject: [xsl] adding a condition to a stylesheet From: marina <marina777uk@xxxxxxxxx> Date: Thu, 9 Jan 2003 03:24:50 -0800 (PST) |
Hi, Using the xml snippet below <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> 24488 </TARGET_CHARACTER_STATUS> <TARGET_CHARACTER_LOCATION_ID> 24488 </TARGET_CHARACTER_LOCATION_ID> <MESSAGE> hello </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> 24411 </LOCATION_ID> <TARGET_CHARACTER_ID> 23212 </TARGET_CHARACTER_ID> <TARGET_CHARACTER_STATUS> 3 </TARGET_CHARACTER_STATUS> <TARGET_CHARACTER_LOCATION_ID> 24411 </TARGET_CHARACTER_LOCATION_ID> <MESSAGE> hi </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> 24488 </TARGET_CHARACTER_LOCATION_ID> <MESSAGE> yes </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> 293 </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> no </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> 10010 </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> just </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> PAGE </USAGE> <MESSAGE_TYPE> STD </MESSAGE_TYPE> <CHARACTER_ID> 10010 </CHARACTER_ID> <CHARACTER_STATUS> 3 </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> test</MESSAGE> <TIME> 'Tue, 01 Jan 2002 20:28:08 +0000' </TIME> </DIRECT> </LOG> ----------------------------------------------------------------------- I have written a stylesheet that finds the number of messages where the <LOCATION_ID> is the not same as the <TARGET_CHARACTER_LOCATION_ID>, and after counting the total number of messages I also know how many were sent where the location id was the same. ----------------------------------------------------------------------- Here is my stylesheet <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="text"/> <xsl:key name="kLoc" match="LOCATION_ID[not(. = ../preceding-sibling::DIRECT[1] /TARGET_CHARACTER_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(LOG/*[number(TARGET_CHARACTER_LOCATION_ID) != number(LOCATION_ID)])"/> <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> ----------------------------------------------------------------------- And here is the output The total number of messages sent was: 6 The total number of messages sent to a different location was 2 The total number of messages sent to the same location was 4 ----------------------------------------------------------------------- All works ok. What I am stuck with is how to only test those <DIRECT> nodes where the <USAGE> tag contains TELL and not PAGE (as you see the last DIRECT nodes USAGE tag is PAGE) This would also have to be taken into account when counting the messages. So in summary I need a total number of DIRECT nodes where the USAGE is TELL and of them how many where <LOCATION_ID> is the not same as the <TARGET_CHARACTER_LOCATION_ID> and how many where it is. ( I will after need to reverse it after to look for DIRECT nodes with PAGE and not TELL). I am stuck as to how to do this addition. Many thanks for any help, Marina __________________________________________________ Do you Yahoo!? Yahoo! Mail Plus - Powerful. Affordable. Sign up now. http://mailplus.yahoo.com XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] xslt style, Jeni Tennison | Thread | Re: [xsl] adding a condition to a s, Francis Norton |
RE: [xsl] how to capture a value re, Anthony Kong | Date | RE: [xsl] adding a condition to a s, Heinz Seldte |
Month |
Keywords