|
Subject: Re: [xsl] double condition syntax From: marina <marina777uk@xxxxxxxxx> Date: Sat, 7 Feb 2004 09:34:03 -0800 (PST) |
Hi Jeni,
Many thanks for that. I put in the expression and got
the second condition to work correctly for one
variable, but it seems not to work on the other.
Here's an xml snippet
------------------------------------------
<LOG>
<DIRECT>
<LOCATION_ID> 24 </LOCATION_ID>
<TARGET_CHARACTER_LOCATION_ID> 2799
</TARGET_CHARACTER_LOCATION_ID>
<MESSAGE> hello </MESSAGE>
</DIRECT>
<DIRECT>
<LOCATION_ID> 24488 </LOCATION_ID>
<TARGET_CHARACTER_LOCATION_ID> 2455
</TARGET_CHARACTER_LOCATION_ID>
<MESSAGE> hello </MESSAGE>
</DIRECT>
<DIRECT>
<LOCATION_ID> 23388 </LOCATION_ID>
<TARGET_CHARACTER_LOCATION_ID> 266
</TARGET_CHARACTER_LOCATION_ID>
<MESSAGE> hello </MESSAGE>
</DIRECT>
<DIRECT>
<LOCATION_ID> 293 </LOCATION_ID>
<TARGET_CHARACTER_LOCATION_ID> 293
</TARGET_CHARACTER_LOCATION_ID>
<MESSAGE> no </MESSAGE>
</DIRECT>
<DIRECT>
<LOCATION_ID> 31132 </LOCATION_ID>
<TARGET_CHARACTER_LOCATION_ID> 31132
</TARGET_CHARACTER_LOCATION_ID>
<MESSAGE> no </MESSAGE>
</DIRECT>
<DIRECT>
<LOCATION_ID> 24488 </LOCATION_ID>
<TARGET_CHARACTER_LOCATION_ID> 24488
</TARGET_CHARACTER_LOCATION_ID>
<MESSAGE> no </MESSAGE>
</DIRECT>
</LOG>
-----------------------------------------------
3 different locations all duplicate messages and 3 the
same locations with duplicate messages.
Here's my new stylesheet
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text"/>
<xsl:variable name="vTotalSent"
select="count(LOG/*/MESSAGE)"/>
<xsl:variable name="vNumNotSame"
select="count(LOG/*[number(LOCATION_ID) !=
number(TARGET_CHARACTER_LOCATION_ID) and
preceding-sibling::*[1]/MESSAGE !=
MESSAGE])"/>
<xsl:variable name="vNumSame"
select="count(LOG/*[number(LOCATION_ID) =
number(TARGET_CHARACTER_LOCATION_ID) and
preceding-sibling::*[1]/MESSAGE !=
MESSAGE])"/>
<xsl:template match="/">
<xsl:text> The total number of messages sent was:
</xsl:text>
<xsl:value-of select="$vTotalSent"/>
<xsl:text> The total number of messages sent to a
different location was </xsl:text>
<xsl:value-of select="$vNumNotSame"/>
<xsl:text> The total number of messages sent to the
same location was </xsl:text>
<xsl:value-of select="$vNumSame"/>
</xsl:template>
</xsl:stylesheet>
-------------------------------------------
And my output 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 1
--------------------------------
So it correctly removed the duplicates from messages
sent to the same location, but counted 0 for the first
three different locations, instead of 1.
It must be something simple, but I can't see the
error.
Kind Regards
Marina
--- Jeni Tennison <jeni@xxxxxxxxxxxxxxxx> wrote:
> Hi Marina,
>
> > 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.
>
> The current node-set is constructed with:
>
> LOG/*[number(TARGET_CHAR_LOCATION_ID) !=
> number(LOCATION_ID)]
>
> To get the immediately preceding sibling of the
> element you're looking
> at, you need:
>
> preceding-sibling::*[1]
>
> To get its <MESSAGE> element child, you need:
>
> preceding-sibling::*[1]/MESSAGE
>
> And to make sure that it's not the same as the
> context element's
> <MESSAGE> element, you need:
>
> preceding-sibling::*[1]/MESSAGE != MESSAGE
>
> You need to test this condition *and* the one that
> you've got at the
> moment, so the final path is:
>
> LOG/*[number(TARGET_CHAR_LOCATION_ID) !=
> number(LOCATION_ID) and
> preceding-sibling::*[1]/MESSAGE != MESSAGE]
>
> So to set $vNumNotSame, you need:
>
> <xsl:variable name="vNumNotSame"
>
> select="count(LOG/*[number(TARGET_CHAR_LOCATION_ID)
> !=
> number(LOCATION_ID) and
>
> preceding-sibling::*[1]/MESSAGE !=
> MESSAGE])"/>
>
> Note that you probably want to change how to
> calculate the number of
> messages sent to the *same* location, since it now
> isn't the same as
> $vTotalSent - $vNumNotSame.
>
> Cheers,
>
> Jeni
>
> ---
> Jeni Tennison
> http://www.jenitennison.com/
>
>
> XSL-List info and archive:
> http://www.mulberrytech.com/xsl/xsl-list
>
__________________________________
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
| Current Thread |
|---|
|
| <- Previous | Index | Next -> |
|---|---|---|
| Re: [xsl] double condition syntax, Jeni Tennison | Thread | [xsl] Matching all elements in a na, Kjetil Kjernsmo |
| Re: [xsl] double condition syntax, Jeni Tennison | Date | [xsl] Matching all elements in a na, Kjetil Kjernsmo |
| Month |