normalize-space function inconsistent results

This should cover W3C XML Schema, Relax NG and DTD related problems.
Richard_Wood
Posts: 12

normalize-space function inconsistent results

Thu Jun 30, 2016 11:59 pm

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)
Radu
Posts: 5088

Re: normalize-space function inconsistent results

Fri Jul 01, 2016 7:57 am

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
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com

Return to “XML Schemas”

Who is online

Users browsing this forum: No registered users and 0 guests