[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Finding and processing index terms
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 ________________________________________________________________________
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|