Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old October 13th, 2008, 04:52 PM
Authorized User
Join Date: Jun 2008
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Default Simple != problem

The document that I'm expecting should only contain 'apple' or 'oranges' or 'tomatoes'. Anything but I will give the element's text a value of 'invalid', otherwise it's 'valid'.

Below expressions would still return false when 'oranges' or 'tomatoes' is present. The same answer I will get when I use "not(contains(.'apples')) or not(contains..."

.!='apple' or .!='oranges' or .!='tomatoes'


(.!='apple') or (.!='oranges') or (.!='tomatoes')

So I used in choose-when construct '=' instead

.='apple' or .='oranges' or .='tomatoes'

Why is != behaving differently?

Old October 13th, 2008, 05:06 PM
mhkay's Avatar
Wrox Author
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts

The expression

.!='oranges' or .!='tomatoes'

is always true. If the value of "." is 'oranges', then .!='tomatoes' is true; if the value is 'tomatoes', then .!='oranges' is true, and if it's anything else, then both are true.

Michael Kay
Author, XSLT 2.0 and XPath 2.0 Programmer's Reference
Old October 13th, 2008, 09:31 PM
Friend of Wrox
Join Date: Jun 2008
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts

In other words, you need

!(.='apple' or .='oranges' or .='tomatoes')

which is the equivalent of

(.!='apple' and .!='oranges' and .!='tomatoes')
Old October 13th, 2008, 11:54 PM
Authorized User
Join Date: Jun 2008
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts

Thanks for the explanation, Mike!

Old Pedant, Thanks too. I will use !(.='apple'...) construct...

Similar Threads
Thread Thread Starter Forum Replies Last Post
A Simple Problem paole Wrox Book Feedback 7 July 23rd, 2007 08:55 PM
Simple Problem Little Shell XML 2 June 5th, 2006 03:30 PM
Simple problem rsa3des Classic ASP Basics 4 August 8th, 2005 06:14 PM
a simple problem aquarius XSLT 1 February 27th, 2004 06:17 AM
Simple Problem bsdb3 Java GUI 2 February 5th, 2004 09:05 PM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.