normalize-space function inconsistent results
This should cover W3C XML Schema, Relax NG and DTD related problems.
-
- Posts: 16
- Joined: Tue Jan 12, 2016 9:41 pm
normalize-space function inconsistent results
Post 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:
<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)
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)
-
- Posts: 9431
- Joined: Fri Jul 09, 2004 5:18 pm
Re: normalize-space function inconsistent results
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:
Retrieve all "dataProvider" elements from any "Document" element with the condition that their normalized text content is not empty.
while this XPath means:
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
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(.)]
while this XPath means:
Code: Select all
//Document/dataProvider/normalize-space()
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
<oXygen/> XML Editor
http://www.oxygenxml.com
Jump to
- Oxygen XML Editor/Author/Developer
- ↳ Feature Request
- ↳ Common Problems
- ↳ DITA (Editing and Publishing DITA Content)
- ↳ SDK-API, Frameworks - Document Types
- ↳ DocBook
- ↳ TEI
- ↳ XHTML
- ↳ Other Issues
- Oxygen XML Web Author
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Content Fusion
- ↳ Feature Request
- ↳ Common Problems
- Oxygen JSON Editor
- ↳ Feature Request
- ↳ Common Problems
- Oxygen PDF Chemistry
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Feedback
- ↳ Feature Request
- ↳ Common Problems
- Oxygen XML WebHelp
- ↳ Feature Request
- ↳ Common Problems
- XML
- ↳ General XML Questions
- ↳ XSLT and FOP
- ↳ XML Schemas
- ↳ XQuery
- NVDL
- ↳ General NVDL Issues
- ↳ oNVDL Related Issues
- XML Services Market
- ↳ Offer a Service