yonan2236
yonan2236

Reputation: 13659

Xpath Expression Interpretation

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.

Upvotes: 1

Views: 93

Answers (2)

hr_117
hr_117

Reputation: 9627

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)

Upvotes: 0

Michael Kay
Michael Kay

Reputation: 163625

//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.

Upvotes: 4

Related Questions