xsl-list
[Top] [All Lists]

double condition syntax

2004-02-07 05:51:25
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="'&#xA;'"/>
  
  <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



<Prev in Thread] Current Thread [Next in Thread>