Support #6500
closedoutput.principalResult always NULL when using transform
0%
Description
I need to get an HTML document from an XML file and its XSL. I'm running on node.js 18.16, Windows 11
Here's the code:
const xmlString = fs.readFileSync('path/to/xml'); const xslString = fs.readFileSync('path/to/xsl');
const transformationOptions = { styleSheetText: xslString, sourceType: 'xml', destination: 'serialized', logLevel: 10 } SaxonJS.transform(transformationOptions, "async") .then(output=>{ console.log(output.principalResult); }) .catch(err => { console.error(err) }
And here's the output (running on command line, node transform.js) Asynchronous transform with options: stylesheetText={"N":"package", "version":"30",(string, sourceType=xml(string), sourceText=<xfa:datasets xmlns xfa="http:(string), destination=raw(string), logLevel=10(string), SEF generated by SaxonJS 2.6 at 2024-08-08T14:38:31.398+02:00 null
As you can see there's no error, but while the other output properties are filled, this one remains null.
Am I missing something? Thanks in advance Moreno.
Files
Updated by Michael Kay 4 months ago
How does the stylesheet produce its output? Does it use xsl:result-document?
It's always easier to see what's going wrong if we have full details of what you are doing, ideally in a form that we can reproduce ourselves. The stylesheet contents might be irrelevant, but we don't know that without looking at it.
Updated by Moreno Andreo 4 months ago
- File CDAit_v5.xsl CDAit_v5.xsl added
- File CDAit.xsl CDAit.xsl added
Michael Kay wrote in #note-1:
How does the stylesheet produce its output? Does it use xsl:result-document?
It's always easier to see what's going wrong if we have full details of what you are doing, ideally in a form that we can reproduce ourselves. The stylesheet contents might be irrelevant, but we don't know that without looking at it.
You can find the XSL files attached (original file, CDAit.xsl, has output method pointing to HTML 4.01, but it seems it's not supported, so I changed to HTML5 and saved as CDAit_v5.xsl). Before using it, I compiled via
xslt3 -t -xsl: CDAit_v5.xsl -export:CDAit_v5-sef-json -nogo -relocate:on -ns:##html5
and in the project I load the compiled XSL
Updated by Martin Honnen 4 months ago
The option is named stylesheetText
, not styleSheetText
, see https://www.saxonica.com/saxon-js/documentation2/index.html#!api/transform.
Just to be sure, does the problem occur with any of your attempts to run SaxonJS with Node.js and the transform API or just with that particular stylesheet?
If you want us to allow to reproduce the problem consider to add the XML input sample as well, minimal but complete to allow us to run the code and reproduce the error.
Why do you set -ns:##html5
although based on the match patterns in the XSLT you don't process (X)HTML5?
Updated by Moreno Andreo 4 months ago
- File fullCDA2.xml fullCDA2.xml added
Sorry, my bad. It's just a typo. My actual code is correct.
The switch -ns:##html5 was a part of a tutorial I read online (don't remember where, TBH). I tried to compile it without the switch, however, with no results.
You can find attached CDA2 XML document, with fake data, but real structure.
If you need anything else, please just ask. Thanks Moreno.
Updated by Norm Tovey-Walsh 4 months ago
Looking at fullCDA2.xml
(and cda2.xml
), we find:
<xfa:datasets xmlns:xfa="http://www.xfa.org/schema/xfa-data/1.0/">
<xfa:data>
<xfa:datasets>
<xfa:data>
<ClinicalDocument xmlns="urn:hl7-org:v3" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
...
but the document template in your stylesheet is:
<xsl:template match="/">
<xsl:apply-templates select="n1:ClinicalDocument"/>
</xsl:template>
That will only work if n1:ClinicalDocument
is the document element of the input document, which it isn't.
If I modify your stylesheet to apply templates to //n1:ClinicalDocument
it produces some output...
I hope that helps.
Updated by Moreno Andreo 4 months ago
I finally managed to get an error, using the attached file (I wasn't aware that the transformation wanted just the ClinicalDocument and not with the XFA tags).
This is the error I get
Asynchronous transform with options: stylesheetText={"N":"package","version":"30",(string), sourceType=xml(string), sourceText=<ClinicalDocument xmlns="urn:h(string), destination=serialized(string), logLevel=10(string), SEF generated by SaxonJS 2.6 at 2024-08-08T14:38:31.398+02:00 Transformation failure: Error XPTY0004 at CDAit_v5.xsl#1796 Required cardinality of first argument of substring-before() is zero or one; supplied value contains 2 items (xs:untypedAtomic('tel:0111234567'), xs:untypedAtomic('mailto://mariapaziente@example.com')) ERRORE Transform: XError:Required cardinality of first argument of substring-before() is zero or one; supplied value contains 2 items (xs:untypedAtomic('tel:0111234567'), xs:untypedAtomic('mailto://mariapaziente@example.com')); code:XPTY0004
Updated by Norm Tovey-Walsh 4 months ago
That's an error in your stylesheet, I'm afraid, and not a SaxonJS problem. I think the problem is that there are multiple telcom
elements in the patient record:
<recordTarget>
<patientRole classCode="PAT">
...
<telecom use="HP" value="tel:01119665793" />
<telecom use="HP" value="mailto://mapilalla@gmail.com" />
So when you call show-telcom
:
<xsl:call-template name="show-telecom">
<xsl:with-param name="telecom" select="$contact/n1:telecom"/>
</xsl:call-template>
You're passing two telcom
elements to the template. That means that in your attempt to take the substring before:
<xsl:when test="$telecom">
<xsl:variable name="type" select="substring-before($telecom/@value, ':')"/>
you're passing a sequence to the function and that isn't allowed. Without understanding the data more completely, it's hard to suggest what fix is most appropriate. You could process them as a sequence, or only process one of them.
Good luck!
Please register to edit this issue
Also available in: Atom PDF Tracking page