Well, it all depends what you think a node is. The node() test matches all types of nodes, i.e. comment, PI, element and text nodes, so if you're getting the "wrong" answer, then you're using the wrong test!
I don't see how you get 30 from the sample XML you posted, nor do I see why you expect 20. I suggest you look at the alternatives to node() at
http://www.w3.org/TR/xpath and decide which one(s) you want to count.