Bug #5039
closedChaining two XSLTs where the first creates a fragment with two element children works under Node.js but not in the browser
100%
Description
When I run the code
const SaxonJS = require("saxon-js")
const xslt1Source = `<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="3.0"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="#all">
<xsl:mode on-no-match="shallow-copy"/>
<xsl:template match="data">
<h1><xsl:value-of select="name" /></h1>
<div>Age: <xsl:value-of select="age" /></div>
</xsl:template>
</xsl:stylesheet>`;
const xslt2Source = `<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="3.0"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="#all">
<xsl:mode on-no-match="shallow-copy"/>
<xsl:template match="h1">
<p>My name is <xsl:value-of select="." />!</p>
</xsl:template>
</xsl:stylesheet>`;
const xmlSource = `<data>
<name>John</name>
<age>25</age>
</data>`;
const result = SaxonJS.XPath.evaluate(`
fold-left(
$xsltSources,
parse-xml($xmlSource),
function($node, $xsltText) {
transform(
map {
'source-node' : $node,
'stylesheet-text': $xsltText
}
)?output
}
)`, [], { 'params' : { 'xmlSource' : xmlSource, 'xsltSources' : [xslt1Source, xslt2Source] } })
console.log(SaxonJS.serialize(result));
under Node.js it works fine and outputs <p>My name is John!</p><div>Age: 25</div>
.
Trying to run the same (minus the first line with the require
call) in the browser gives an error "Uncaught DOMException: Failed to execute 'appendChild' on 'Node': Only one element on document allowed." in SaxonJS2.js:4407.
So somehow it seems the Node.js version manages to create a document fragment node with two element children while the browser version seems to try to put two element nodes into a document node.
The error only occurs when trying to chain the two stylesheets, the first run alone creating the fragment with two element children runs fine.
Please register to edit this issue
Also available in: Atom PDF Tracking page