[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] double condition syntax
Hi, With the following xml snippet, I wrote an xslt stylesheet to count the number of messages that go to either the same or different locations. -------------------------------------------- xml snippet <LOG> <DIRECT> <COMM_TYPE> PAGETELL </COMM_TYPE> <MESSAGE_TYPE> EMOTE </MESSAGE_TYPE> <CHARACTER_ID> 10010 </CHARACTER_ID> <LOCATION_ID> 24488 </LOCATION_ID> <TARGET_CHAR_ID> 18735 </TARGET_CHAR_ID> <TARGET_CHAR_LOCATION_ID> 24488 </TARGET_CHAR_LOCATION_ID> <MESSAGE> hello </MESSAGE> </DIRECT> <DIRECT> <COMM_TYPE> PAGETELL </COMM_TYPE> <MESSAGE_TYPE> EMOTE </MESSAGE_TYPE> <CHARACTER_ID> 10010 </CHARACTER_ID> <LOCATION_ID> 24488 </LOCATION_ID> <TARGET_CHAR_ID> 18735 </TARGET_CHAR_ID> <TARGET_CHAR_LOCATION_ID> 24488 </TARGET_CHAR_LOCATION_ID> <MESSAGE> hello </MESSAGE> </DIRECT> <DIRECT> <COMM_TYPE> PAGETELL </COMM_TYPE> <MESSAGE_TYPE> EMOTE </MESSAGE_TYPE> <CHARACTER_ID> 76555 </CHARACTER_ID> <LOCATION_ID> 43222 </LOCATION_ID> <TARGET_CHAR_ID> 18735 </TARGET_CHAR_ID> <TARGET_CHAR_LOCATION_ID> 77799 </TARGET_CHAR_LOCATION_ID> <MESSAGE> goodbye </MESSAGE> </DIRECT> </LOG> -------------------------------------------------- the xslt <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="text"/> <xsl:variable name="NL" select="'
'"/> <xsl:variable name="vTotalSent" select="count(LOG/*/MESSAGE)"/> <xsl:variable name="vNumNotSame" select="count(LOG/*[number(TARGET_CHAR_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> --------------------------------------------------- Produces the following output. The total number of messages sent was: 3 The total number of messages sent to a different location was 1 The total number of messages sent to the same location was 2 -------------------------------------------------- I need to add a second condition to variable 'vNumNotSame' that also checks to see if the MESSAGE was the same as the previous sibling MESSAGE, and if so NOT to count it. So with the above snippet the new output should be The total number of messages sent was: 3 The total number of messages sent to a different location was 1 The total number of messages sent to the same location was 1 <------- ignored the duplicate. Thanks for any help, Marina. __________________________________ Do you Yahoo!? Yahoo! Finance: Get your refund fast by filing online. http://taxes.yahoo.com/filing.html XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|