Project

Profile

Help

Support #6500

closed

output.principalResult always NULL when using transform

Added by Moreno Andreo 3 months ago. Updated 3 months ago.

Status:
Closed
Priority:
Low
Assignee:
-
Category:
-
Sprint/Milestone:
-
Start date:
2024-08-09
Due date:
% Done:

0%

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

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

CDAit_v5.xsl (85.9 KB) CDAit_v5.xsl Moreno Andreo, 2024-08-09 15:24
CDAit.xsl (85.9 KB) CDAit.xsl Moreno Andreo, 2024-08-09 15:26
fullCDA2.xml (99 KB) fullCDA2.xml Moreno Andreo, 2024-08-12 11:53
cda2.xml (198 KB) cda2.xml Moreno Andreo, 2024-08-12 13:10
cda2.xml (198 KB) cda2.xml Moreno Andreo, 2024-08-12 13:35
Actions #1

Updated by Michael Kay 3 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.

Actions #2

Updated by Moreno Andreo 3 months ago

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

Actions #3

Updated by Martin Honnen 3 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?

Actions #4

Updated by Moreno Andreo 3 months ago

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.

Actions #5

Updated by Moreno Andreo 3 months ago

Sorry, the right file

Actions #6

Updated by Norm Tovey-Walsh 3 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.

Actions #7

Updated by Moreno Andreo 3 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://')) 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://')); code:XPTY0004

Actions #8

Updated by Norm Tovey-Walsh 3 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!

Actions #9

Updated by Norm Tovey-Walsh 3 months ago

  • Status changed from New to Closed

Please register to edit this issue

Also available in: Atom PDF Tracking page