[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Problem with "except" operator

Subject: Re: Problem with "except" operator
From: Felix Nensa <nensa@xxxxxxxx>
Date: Wed, 11 Feb 2009 15:19:33 +0100
Re:  Problem with "except" operator
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

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.