Re: [xsl] How to efficently determine if a nodes exists with an attribute value other than those in a list

Subject: Re: [xsl] How to efficently determine if a nodes exists with an attribute value other than those in a list
From: David Carlisle <davidc@xxxxxxxxx>
Date: Tue, 7 Aug 2007 22:10:28 +0100
> > > doc/*[(not(@type=$tcheck))]

> This however is a little less intuitive.  Checking an attribute
> against a sequence for equality seems a little suprising, I'd expect
> an "in" operator or some such thing (let me guess, XSLT 1.0
> compatability?),

well of course xslt1 doesn't have sequences of strings (or nodes for that
matter) but it does have node sets and = (and the other relational
operators) have an implied existential quantification on xslt1 node sets.
If you go in xslt 1
test="foo/bar='a'"
it's true if _any_ bar element is equal to 'a'.

This existential quantifcation carries over in a natural way to xpath2
sequences
$x = $y
is true if _any_ item in $x is equal to _any_ item in $y.
(xpath2 has an eq operator for cases where you don't want to apply to a
complete sequence.)


Note this existential quantification is why you should almost never use
the != operator in XPath, It's almost always better to use not($x=$y),
as in the example above, rather than $x!=$y as when it means the same
thing, you've only lost a few key trokes, and when it means something
else you almost never want $x!=$y which is true if any item of $x is not
equal to an item of $y which means means that in almost all non trivial
cases, it evaluates to true().

David

________________________________________________________________________
The Numerical Algorithms Group Ltd is a company registered in England
and Wales with company number 1249803. The registered office is:
Wilkinson House, Jordan Hill Road, Oxford OX2 8DR, United Kingdom.

This e-mail has been scanned for all viruses by Star. The service is
powered by MessageLabs. 
________________________________________________________________________

Current Thread