1

Can someone please explain what the below Xpath expressions mean?

  1. //node()[not(*)][not(normalize-space())]
  2. //node()[not(*)][not(normalize-space())][not(boolean(@Key))]
  3. //node()[not(text())]

I understand //node() means any node, but not sure with the following expressions.

yonan2236
  • 13,371
  • 33
  • 95
  • 141

2 Answers2

4
//node()[not(*)][not(normalize-space())]

All element, text, comment, and processing-instruction nodes, anywhere in the document, that do not have a child element node and whose string value is either empty or consists entirely of whitespace

//node()[not(*)][not(normalize-space())][not(boolean(@Key))]

As above, with the extra condition that there is no @Key attribute. The last predicate is badly written: it could be shortened to [not(@Key)] without changing its meaning.

//node()[not(text())]

All element, text, comment, and processing-instruction nodes, anywhere in the document, that do not have a child text node.

Michael Kay
  • 156,231
  • 11
  • 92
  • 164
0

Updated (thanks to @Michael Kay comment)
First one:
//node() all nodes in the document (including text, comment and processing instruction but not attributes)
[not(*)] which does not have any child element nodes
[not(normalize-space())] which does not have any text content (beside of whitespace).

Second one: Same as first one but additional:

[not(boolean(@Key))] the node has no attribute Key Update: For the third one have a look to e.g. this In your example this will also ignore nodes with any text content (even white space)

Community
  • 1
  • 1
hr_117
  • 9,589
  • 1
  • 18
  • 23
  • and the third one please? – yonan2236 Mar 21 '16 at 08:31
  • 1
    Not an entirely accurate answer. For example `//node()` does not select all nodes in the document - it doesn't select the document node, and it doesn't select attributes and namespaces; also `[not(*)]` allows child text nodes but not child element nodes.. – Michael Kay Mar 21 '16 at 11:58