Re: [xml] XPath null nodes and false()



On Mon, Apr 01, 2002 at 02:22:19AM +0200, Melvyn Sopacua wrote:
Hi,

first off - the spec isn't very clear:
"A node test that is a QName is true if and only if the type of the node 
(see [5 Data Model]) is the principal node type and has an expanded-name 
equal to the expanded-name specified by the QName. For example, child::para 
selects the para element children of the context node; if the context node 
has no para children, it will select an empty set of nodes."

  That definition is part of 2.3 Node Tests and is intended to set the
rule explaining which nodes actually match a given node set usually in a Path.
  To map that to your example this is used only when selecting nodes to
compute "preceding-sibling::kid" not for the subsequent equality test.

For me, that translates to:
A node test is true .... otherwise it is an empty set of nodes. Since true 
in combination with otherwise, usually gives 'false', I assume that an 
empty set of nodes equals false.

  The definition for the = operator is actually given in 3.4 Booleans
The specific case for this comparison is a node-set against a boolean:

"If one object to be compared is a node-set and the other is a boolean,
 then the comparison will be true if and only if the result of performing
 the comparison on the boolean and on the result of converting the node-set
 to a boolean using the boolean function is true."

 Then http://www.w3.org/TR/xpath#function-boolean states
 "a node-set is true if and only if it is non-empty"

 So you are right in your expectation but not for the right reason :-)

However - the following illustrates it doesn't:
<xsl:when test="preceding-sibling::kid = false()">
<xsl:when test="count(preceding-sibling::kid) = 0">

  There was a bug in the equality function:
paphio:~/XML -> ./testXPath "/example"
Object is a Node Set :
Set contains 0 nodes:
paphio:~/XML -> ./testXPath "/example = false()"
Object is a Boolean : false
paphio:~/XML -> ./testXPath "count(/example) = 0"
Object is a Boolean : true
paphio:~/XML -> ./testXPath "/EXAMPLE"
Object is a Node Set :
Set contains 1 nodes:
1  ELEMENT EXAMPLE
    ATTRIBUTE prop1
      TEXT
        content=gnome is great
    ATTRIBUTE prop2
      TEXT
        content=& linux too
paphio:~/XML -> ./testXPath "/EXAMPLE = false()"
Object is a Boolean : true
paphio:~/XML -> ./testXPath "count(/EXAMPLE) = 0"
Object is a Boolean : false
paphio:~/XML -> 

  There is a one line change in xpath.c to fix it, patch enclosed:

paphio:~/XML -> ./testXPath "/example = false()"
Object is a Boolean : true
paphio:~/XML -> ./testXPath "count(/example) = 0"
Object is a Boolean : true
paphio:~/XML -> ./testXPath "/EXAMPLE = false()"
Object is a Boolean : false
paphio:~/XML -> ./testXPath "count(/EXAMPLE) = 0"
Object is a Boolean : false
paphio:~/XML -> 

  Thanks for the report,

Daniel

-- 
Daniel Veillard      | Red Hat Network https://rhn.redhat.com/
veillard redhat com  | libxml GNOME XML XSLT toolkit  http://xmlsoft.org/
http://veillard.com/ | Rpmfind RPM search engine http://rpmfind.net/

Attachment: xpath.patch
Description: Text document



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]