Project

Profile

Help

deliverResultDocument option of transform function

Added by Martin Honnen about 2 months ago

I am trying to understand how xsl:result-documents can be handled with Node and Saxon-JS 2 and the async use of the transform function. The documentation at http://saxonica.com/saxon-js/documentation/index.html#!api/transform is rather long but in the section about deliverResultDocument it says:

If the save property is absent, the default implementation saves the value in options.resultDocuments[URI], for return to the calling application.

Is that meant to say that the option passed into transform receives these result documents in a resultDocuments object? Or is the result the Promise returns supposed to have a resultDocuments property by default?

I suppose the latter is meant.

However, when trying to rely on that default, I get an error:

PS C:\Users\marti\SomeDir> node .\return-xml-test1.js
Transformation failure: TypeError: N.save is not a function
TypeError: N.save is not a function
    at e (C:\Users\marti\node_modules\saxon-js\SaxonJS2N.js:778:362)
    at C:\Users\marti\node_modules\saxon-js\SaxonJS2N.js:782:192
    at b (C:\Users\marti\node_modules\saxon-js\SaxonJS2N.js:357:642)
    at C:\Users\marti\node_modules\saxon-js\SaxonJS2N.js:357:865
    at Array.forEach (<anonymous>)
    at C:\Users\marti\node_modules\saxon-js\SaxonJS2N.js:357:838
    at C:\Users\marti\node_modules\saxon-js\SaxonJS2N.js:357:865
    at Array.forEach (<anonymous>)
    at C:\Users\marti\node_modules\saxon-js\SaxonJS2N.js:357:838
    at C:\Users\marti\node_modules\saxon-js\SaxonJS2N.js:388:385
    at C:\Users\marti\node_modules\saxon-js\SaxonJS2N.js:401:122
    at C:\Users\marti\node_modules\saxon-js\SaxonJS2N.js:357:865
    at Array.forEach (<anonymous>)
    at C:\Users\marti\node_modules\saxon-js\SaxonJS2N.js:357:838
    at Object.push (C:\Users\marti\node_modules\saxon-js\SaxonJS2N.js:406:435)
    at c (C:\Users\marti\node_modules\saxon-js\SaxonJS2N.js:5423:371)
    at C:\Users\marti\node_modules\saxon-js\SaxonJS2N.js:5463:480

The Javascript code is

require('saxon-js');

SaxonJS.transform(
    {
        'stylesheetFileName': 'return-xml-test1.sef',
        'destination': 'document',
        'resultForm': 'default',
        'deliverResultDocument': uri => {
            return { 'destination': 'document' }
        }
    },
    'async'
    )
    .then(result => console.log(result))
    .catch(error => console.log(error)
);

the stylesheet as XSLT is

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    version="3.0"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:array="http://www.w3.org/2005/xpath-functions/array"
    xmlns:ixsl="http://saxonica.com/ns/interactiveXSLT"
    expand-text="yes"
    exclude-result-prefixes="#all">

  <xsl:output method="xml" indent="yes"/>

  <xsl:template name="xsl:initial-template">
    <root>prinicipal result</root>
    <xsl:iterate select="1 to 5">
        <xsl:call-template name="output-xml">
          <xsl:with-param name="value" select="."/>
        </xsl:call-template>
    </xsl:iterate>
  </xsl:template>

  <xsl:template name="output-xml">
    <xsl:param name="value"/>
    <xsl:result-document href="xml-result-{$value}.xml" method="xml">
      <result name="result-{$value}">Result {$value}</result>
    </xsl:result-document>
  </xsl:template>

</xsl:stylesheet>

Have I misunderstood that sentence about "If the save property is absent, the default implementation saves the value in options.resultDocuments[URI]"?


Replies (1)

RE: deliverResultDocument option of transform function - Added by Michael Kay about 2 months ago

We made a fairly late change, so that with asynchronous operation the supplied options object is not modified. If we were to modify it, that would create problems if another transformation is initiated before the first one is finished. So the result object -- the object passed to the then() method of the promise -- is in fact a new object. It will have an entry called principalResult to contain the principal result, and an entry called resultDocuments which is a map/object containing the secondary result documents indexed by URI.

Looking at the API tests I see there are (perhaps inevitably) many combinations involving secondary result documents with the asynchronous API that haven't been tested, and I'll add some more tests to investigate.

    (1-1/1)

    Please register to reply