Dear Shuxin,

> Both Saxon and BaseX return the result node set [1, 2]. However, the nodes 
> with id 2 and 3 seems identical to me and is hard to understand why node 2 is 
> selected while 3 is not. If node 2 is deleted from the XML document, result 
> set [1,3] is returned. I'm interested in whether this is intended behavior 
> which I might have limited knowledge of? If it is also of interest for you 
> you may have a look. Thank you very much!

The semantics here are tricky:

• boolean(.) gives you true() or false()
• true() is returned for all 3 elements
• xs:double(true()) returns 1, so your query is equivalent to //*[1]
• ...[1] returns the first item of the input
• //* returns the 3 elements P1, A1 (id="2") and A1 (id="3")
• //* is a shortcut for /descendant-or-self::node()/child::*
• /descendant-or-self::node() returns 7 results (1 document, 3
elements, 3 texts)
• the document has 1 P1 child node; P1 has 2 A1 child nodes
• //*[1] returns a) the P1 child node and b) the first A1 child node

…and Martin was faster with his response, as I just see ;)

If you want to get only the first result of all results, you can use
parentheses: (//*[.....])[1]

Hope this helps,
Christian

Reply via email to