Re: [xsl] Problem with "except" operator

Subject: Re: [xsl] Problem with "except" operator
From: Felix Nensa <nensa@xxxxxxxx>
Date: Wed, 11 Feb 2009 15:19:33 +0100
Thank you guys... works like a charm now :-)

2009/2/11 G. Ken Holman <gkholman@xxxxxxxxxxxxxxxxxxxx>:
> At 2009-02-11 14:44 +0100, Felix Nensa wrote:
>>
>> I have a weird problem where the "except" operator does not behave as
>> I would expect it.
>
> You are incorrectly treating "except" with node values, instead of as node
> identity.
>
>> Given the following input source XML:
>>
>> <root>
>>  <Response>
>>    <Users>
>>      <Count>2</Count>
>>      <User>
>>        <Username>henry</Username>
>>        <Online>false</Online>
>>        <UserId>302</UserId>
>>      </User>
>>      <User>
>>        <Username>felix</Username>
>>        <Online>false </Online>
>>        <UserId>288</UserId>
>>      </User>
>>    </GetUserList>
>>  </Response>
>>  <Response>
>>    <Friends>
>>      <Count>1</Count>
>>      <Friend>
>>        <UserId>288</UserId>
>>      </Friend>
>>    </Friends>
>>  </Response>
>> </root>
>>
>> I am trying to get all those Users wich are not in the list of Friends
>> with the following expression:
>>
>> <xsl:variable name="users" select="//Users/User/UserId" />
>> <xsl:variable name="friends" select="//Friends/Friend/UserId" />
>>
>> <!-- debug output -->
>> <xsl:value-of select="$users except $friends" />
>>
>> It outputs: 302 288
>> I would expect: 302
>
> The expression:
>
>  $A except $B
>
> ... will give you those nodes in $A that are not also nodes in $B.  Not the
> values of the nodes, but the nodes themselves.
>
>> I am using the latest version of Saxon.
>
> Always a wise choice!
>
> You want to deal with node value by using the "=" operator ... I have an
> example below.  Checking a scalar against the set returns false when the
> operator is false for all members of the set, or true when the operator is
> true for any member of the set.
>
> I hope this helps.
>
> . . . . . . . Ken
>
> T:\ftemp>type felix.xml
> <root>
>  <Response>
>    <Users>
>      <Count>2</Count>
>      <User>
>        <Username>henry</Username>
>        <Online>false</Online>
>        <UserId>302</UserId>
>      </User>
>      <User>
>        <Username>felix</Username>
>        <Online>false </Online>
>        <UserId>288</UserId>
>      </User>
>    </Users>
>  </Response>
>  <Response>
>    <Friends>
>      <Count>1</Count>
>      <Friend>
>        <UserId>288</UserId>
>      </Friend>
>    </Friends>
>  </Response>
> </root>
>
> T:\ftemp>type felix.xsl
> <?xml version="1.0" encoding="US-ASCII"?>
> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
>                version="2.0">
>
> <xsl:output method="text"/>
>
> <xsl:template match="/">
> <xsl:variable name="users" select="//Users/User/UserId" />
> <xsl:variable name="friends" select="//Friends/Friend/UserId" />
>
> <!-- debug output -->
> <xsl:value-of select="$users [. != $friends]" />
> </xsl:template>
>
> </xsl:stylesheet>
> T:\ftemp>xslt2 felix.xml felix.xsl
> 302
> T:\ftemp>
>
> --
> Upcoming hands-on XSLT, UBL & code list hands-on training classes:
> Brussels, BE 2009-03;  Prague, CZ 2009-03, http://www.xmlprague.cz
> Training tools: Comprehensive interactive XSLT/XPath 1.0/2.0 video
> Video lesson:    http://www.youtube.com/watch?v=PrNjJCh7Ppg&fmt=18
> Video overview:  http://www.youtube.com/watch?v=VTiodiij6gE&fmt=18
> G. Ken Holman                 mailto:gkholman@xxxxxxxxxxxxxxxxxxxx
> Crane Softwrights Ltd.          http://www.CraneSoftwrights.com/s/
> Male Cancer Awareness Nov'07  http://www.CraneSoftwrights.com/s/bc
> Legal business disclaimers:  http://www.CraneSoftwrights.com/legal
>
>



-- 
Felix Nensa
CTO

zeec GmbH
Neusser Str. 28
50670 Cologne
Germany

mail: felix.nensa@xxxxxxxx
phone: +49 221 37997 472
fax: +49 221 37997 450
mobile: +49 171 958 51 40
web: www.zeec.biz

Current Thread