Should fn:transform in XSLT 3 or SaxonJS.XPath.evaluate support both XSLT and SEF stylesheets?
Added by Martin Honnen over 3 years ago
On the Java side, it seems and the documentation suggests that you can use both normal XSLT documents (e.g. .xsl
files) and SEF exports (e.g. .sef
files) with any API where a stylesheet source is provided. It also works fine with the XPath 3.1 fn:transform
function for me to provide either an XSLT file or a SEF file for the stylesheet-location
so the following works to run both type of stylesheets
transform(
map {
'stylesheet-location' : 'https://martin-honnen.github.io/xslt/2021/includes/base-uri-test1-relocate-off.xsl.sef',
'source-location' : 'https://martin-honnen.github.io/xslt/2021/sample-uris1.xml'
}
)?output/uris/uri/@resolve-uri/data(),
'----',
transform(
map {
'stylesheet-location' : 'https://martin-honnen.github.io/xslt/2021/includes/base-uri-test1.xsl',
'source-location' : 'https://martin-honnen.github.io/xslt/2021/sample-uris1.xml'
}
)?output/uris/uri/@resolve-uri/data()
Even stylesheet-text
works with both .xsl and .sef files e.g.
transform(
map {
'stylesheet-text' : 'https://martin-honnen.github.io/xslt/2021/includes/base-uri-test1-relocate-off.xsl.sef' => unparsed-text(),
'source-location' : 'https://martin-honnen.github.io/xslt/2021/sample-uris1.xml'
}
)?output/uris/uri/@resolve-uri/data(),
'----',
transform(
map {
'stylesheet-base-uri' : 'https://martin-honnen.github.io/xslt/2021/includes/base-uri-test1.xsl',
'stylesheet-text' : 'https://martin-honnen.github.io/xslt/2021/includes/base-uri-test1.xsl' => unparsed-text(),
'source-location' : 'https://martin-honnen.github.io/xslt/2021/sample-uris1.xml'
}
)?output/uris/uri/@resolve-uri/data()
With Saxon JS 2.3, however, I am struggling to provide an .sef.json
as the stylesheet-location
or stylesheet-text
the fn:transform
function, it seems Saxon tries to parse the stylesheet as XML and obviously fails.
Is that intended?
Or should Saxon-JS handle .sef.json
for fn:transform
the same as Saxon Java handles .sef
?
One test case is at https://martin-honnen.github.io/xslt/2021/transformFunctionTest3.html, doing
const result = SaxonJS.XPath.evaluate(`
transform(
map {
'stylesheet-base-uri' : 'https://martin-honnen.github.io/xslt/2021/includes/base-uri-test1.xsl-relocate-off.sef.json',
'stylesheet-text' : 'includes/base-uri-test1.xsl-relocate-off.sef.json' => unparsed-text(),
'source-node' : 'sample-uris1.xml' => doc()
}
)?output/uris/uri/@resolve-uri/data()
`,
[]);
console.log(result);
but throwing an error "Uncaught at SaxonJS2.js:4529":
code: "FODC0002"
message: "Misplaced or malformed markup: This page contains the following errors:error on line 1 at column 1: Document is empty\nBelow is a rendering of the page up to the first error."
name: "XError"
that suggests the JSON SEF is parsed as XML.
Please register to reply