Re: XPath over DOM with CDATA section and text node sibling

Jonas Sicking <[email protected]> Mon, 28 May 2007 18:32:44 -0700
Newsgroups gmane.comp.mozilla.devel.layout.xslt
Message-ID <[email protected]>
Martin Honnen wrote:
> 
> The DOM data model and the XPath data model differ for the number of 
> child nodes the test element in this XML document has:
>   <root><test><![CDATA[cdata text.]]>normal text.</test></root>
> In the XPath data model the test element has a single text child node, 
> in the DOM data model the test element has two child nodes, a CDATA 
> section node and a text node.
> Mozilla (both Firefox 2.0 release as well as a 3.0a nightly) with this 
> test case
> <http://home.arcor.de/martin.honnen/mozillaBugs/domLevel3/mappingProblem1.html> 
> 
> show the following output:
> 
> Number of nodes: 2
> 
> nodeType: 4; nodeValue: cdata text.
> 
> nodeType: 3; nodeValue: normal text.
> 
> 
> Is that in compliance with 
> <http://www.w3.org/TR/DOM-Level-3-XPath/xpath.html#TextNodes>?
> That says
>   "Instead of returning multiple nodes where XPath sees a single logical 
> text node, only the first non-empty DOM Text  or CDATASection node of 
> any logical XPath text will be returned in the node set."
> so it seems Mozilla should only return one child node, the CDATA section 
> node.

No, this is a known bug. Things work fine if you use normal XSLT and the 
<?xml-stylesheet?> PI, but if you use DOM-XPath functions like 
document.evaluate adjacent text nodes are not merged. This turns out to 
be fairly difficult to fix without degrading performance a lot.

Usually you can work around this by writing your expressions 
differently, though that's not always very easy. Exactly what are you 
trying to do?

/ Jonas