Project

Profile

Help

Bug #5144

open

SaxonJS.XPath.evaluate method fails to select CDATA section node as text() node

Added by Martin Honnen about 3 years ago. Updated about 1 month ago.

Status:
New
Priority:
High
Assignee:
-
Category:
XPath Conformance
Sprint/Milestone:
Start date:
2021-10-24
Due date:
% Done:

0%

Estimated time:
Applies to JS Branch:
2
Fix Committed on JS Branch:
Fixed in JS Release:
SEF Generated with:
Platforms:
Company:
-
Contact person:
-
Additional contact persons:
-

Description

I have run into an odd problem trying to use the Saxon-JS 2.3 browser-side SaxonJS.XPath.evaluate method to select text nodes which are in the original parsed XML marked up as a CDATA section. The native XPath 1.0 implementation of the browser finds them, while Saxon-JS 2 doesn't seem to select them.

Test case is:

<!DOCTYPE html>
<html lang=en>
  <head>
    <meta charset=UTF-8>
    <title>Saxon-JS 2 CDATA section as text node test</title>
    <script src="/Saxon-JS-2.3/SaxonJS2.rt.js"></script>
  </head>
  <body>
    <h1>Saxon-JS 2 CDATA section as text node test</h1>
    <section>
      <h2>XPath tests</h2>
      <script>
const xmlSample1 = `<root>
  <description>description 1<\/description>
  <description><![CDATA[<p>description 2]]><\/description>
<\/root>`;

SaxonJS.getResource({ type: 'xml', text: xmlSample1 })
    .then(doc => {
        const textNodes = SaxonJS.XPath.evaluate(`root/description/text()`, doc, { resultForm: 'array' });

        console.log(textNodes);

        console.log(textNodes.length);
  
        const textNodeCount = SaxonJS.XPath.evaluate(`count(root/description/text())`, doc);
  
        console.log(textNodeCount);
  
        const xpath1TextNodeCount = doc.evaluate(`count(root/description/text())`, doc, null, XPathResult.NUMBER_TYPE).numberValue;
  
        console.log(xpath1TextNodeCount);
    });        
      </script>
    </section>
  </body>
</html>

Output in the console with Chrome is:

[text]
1
1
2

Online at https://martin-honnen.github.io/js/2021/saxon-js-test-cdata-as-text-node1.html.

On Node.js this doesn't seem to occur.

Please register to edit this issue

Also available in: Atom PDF Tracking page