Subject: Re: [xsl] Finding and processing index terms From: David Carlisle <davidc@xxxxxxxxx> Date: Wed, 15 Feb 2006 17:45:14 GMT |
This thread shows the danger of using != Basically it's best avoided unless both sides of the expression are atomic values not node sets. If $a and $b are both atomic values then $a != $b means the same as not($a = $b) however when one (or especially) both $a or $b are node sets these mean very different things, and almost always you want not($a = $b) rather than $a != $b. So I usually find that rather than worry if it's safe to use != it's simpler just to always use not( .. = ...). To see the difference, consider <a> <x a="n"/> <x/> </a> Then ask for all the children of x that don't have an attribute that is 'y' (or the different question, have an a attribute that is not 'y') <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="a"> a: <xsl:value-of select="count(*[@a!='y'])"/> b: <xsl:value-of select="count(*[not(@a='y')])"/> c: <xsl:value-of select="count(*[string(@a)!='y'])"/> </xsl:template> </xsl:stylesheet> $ saxon neq.xml neq.xsl <?xml version="1.0" encoding="utf-8"?> a: 1 b: 2 c: 2 If you had used either form (b) or (c) your answer would not have depended on the attribute being defaulted, as no attribute would work the same way as publicOnly="" which would result in the string "" being compared with 'yes' and both '' and 'No' are not equal to yes. But the first form, using != filters out all elements with no attribute. David ________________________________________________________________________ This e-mail has been scanned for all viruses by Star. The service is powered by MessageLabs. For more information on a proactive anti-virus service working around the clock, around the globe, visit: http://www.star.net.uk ________________________________________________________________________
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: RE: [xsl] Finding and processin, Dan Vint | Thread | Re: [xsl] Finding and processing in, Dan Vint |
RE: RE: [xsl] Finding and processin, Dan Vint | Date | [xsl] How to use & in CDATA field, viniciuscamara |
Month |