This has nothing to do with normalize-space () and everything related to text() .
text() abbreviated for child::text() and selects text nodes that are immediate children of the label element. If you do not delete the text node nodes, the label element in your example has two child text nodes, one of which is all spaces, and the other contains "some label" surrounded by spaces.
BTW, which syntax is better: //label[text()[normalize-space() = 'some label']] vs //label[normalize-space(text()) = 'some label'] and why?
They do different things; one that is better, one that does what you want to achieve.
In XPath 1.0, the first expression selects label elements that have a child text node whose value, after normalizing the spaces, is "some label". The second selects the label elements, whose first child text node, after normalizing the spaces, is "some label". This is because normalize-space () (like all functions that expect a string), if you give it node -set, takes the string value of the first node in node -set.
In XPath 2.0, the first expression selects label elements that have a child text node whose value, after normalizing the spaces, is "some label". The second one selects label elements if they have a child text node, after normalizing the space, it equals "some label", but it causes an error if the label element has more than one child text node. This is because normalize-space () (like all functions that expect a string) atomizes its argument and reports a type error if the length of the atomized sequence is greater than one.
source share