[XSL-LIST Mailing List Archive Home]
[By Thread]
[By Date]
At 2009-02-11 14:44 +0100, Felix Nensa wrote:
You are incorrectly treating "except" with node values, instead of as node identity.
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.
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
<xsl:output method="text"/>
Re: [xsl] Problem with "except" operator
Subject: Re: [xsl] Problem with "except" operator From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx> Date: Wed, 11 Feb 2009 08:48:55 -0500 |
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
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Problem with "except" ope, Andrew Welch | Thread | Re: [xsl] Problem with "except" ope, Felix Nensa |
Re: [xsl] Problem with "except" ope, Andrew Welch | Date | Re: [xsl] Problem with "except" ope, Felix Nensa |
Month |
Keywords