Page 1 of 1

normalize-space function inconsistent results

Posted: Thu Jun 30, 2016 11:59 pm
by Richard_Wood
Can anyone explain why I get different results from normalize-space, depending on how I use it?
In one case it works as expected, in the other case it leaves a space on the end of the value:

Source data contains:

Code: Select all

<dataProvider>              MTY-MITAC                </dataProvider>

<sch:let name="refValue"
value="//Document/dataProvider/normalize-space()"/>
Produces: refValue = MTY-MITAC;

<sch:let name="refValue"
value="//Document/dataProvider[normalize-space()]"/>
Produces: refValue = MTY-MITAC ; (note the extra space at the end)

<sch:let name="refValue"
value="//Document/dataProvider[normalize-space(.)]"/>
Produces: refValue = MTY-MITAC ; (note the extra space at the end)

Re: normalize-space function inconsistent results

Posted: Fri Jul 01, 2016 7:57 am
by Radu
Hi Richard,

Whenever you are using "[" and "]" in an XPath expression it means that you are imposing a condition (the specification calls it a "predicate").
So this XPath means:

Code: Select all

//Document/dataProvider[normalize-space(.)]
Retrieve all "dataProvider" elements from any "Document" element with the condition that their normalized text content is not empty.

while this XPath means:

Code: Select all

//Document/dataProvider/normalize-space()
Retrieve all the normalized text content of the "dataProvider" elements which are directly inside any "Document" element.

So in the first XPath the result is not normalized at all because the normalization is inside a condition.

More about XPath predicates (conditions):

http://www.w3schools.com/xsl/xpath_syntax.asp

Regards,
Radu