Project

Profile

Help

Feature #6355

closed

A new instruction that makes a document available by the document() function

Added by Martynas Jusevicius 5 months ago. Updated 29 days ago.

Status:
Resolved
Priority:
Normal
Category:
IXSL extensions
Sprint/Milestone:
-
Start date:
2024-02-20
Due date:
% Done:

0%

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

Description

ixsl:schedule-action supports @document and @http-request. Both approaches have their advantages. For @schedule-action:

The called template can access the documents using the doc(), document(), doc-available(), json-doc(), unparsed-text(), unparsed-text-available(), and unparsed-text-lines() functions as appropriate (the documents will be found in a local cache and will not involve another request to the server).

For @http-request it's the possibility to fully specify the HTTP request headers. That's what I have been using so har

The problem is that the approaches cannot be combined. In other words, it is not possible to specify HTTP request headers, load documents asynchronously and pass them to templates that use document() What could be the solution to this?

Adding more options to ixsl:schedule-action seems like it would overload the instruction too much. I'm thinking a better idea could be decoupling the HTTP client functionality from the document caching functionality. That could be achieved using a new instruction that caches a document node under the specified URI, thus making it available for document() calls.

For example:

  <xsl:variable name="href" select="http://example.com/doc.xml" as="xs:string"/>
  <ixsl:schedule-action http-request="map{ 'href': $href }">
    <xsl:call-template name="response-callback">
      <xsl:with-param name="href" select="$href"/>
    </xsl:call-template>
  </ixsk:schedule-action>

<xsl:template name="response-callback">
  <xsl:param name="href" as="xs:string"/>

  <ixsl:cache-doc href="$href" select="?body"/>
  <xsl:call-template name="legacy"/>
</xsl:template>

<xsl:template name="legacy">
  <xsl:message select="document('http://example.com/doc.xml')"/> <!-- retrieved from cache -->
</xsl:template>

Actions #1

Updated by Michael Kay 5 months ago

Implementation of a design to replace ixsl:schedule-action and address the issues you raise is well advanced. You can find some of the early thinking here:

https://www.balisage.net/Proceedings/vol25/html/Kay01/BalisageVol25-Kay01.html

though the design has moved on from that starting point, and it won't all be delivered in one go.

Actions #2

Updated by Martynas Jusevicius 5 months ago

Michael, thanks for the update. I'm looking forward for the promise support.

This is about a more trivial issue of making the async-loaded documents accessible using document(). In SaxonJS 2.6, you can either do that or specify the HTTP request headers, but not both.

Actions #3

Updated by Debbie Lockett 29 days ago

  • Category set to IXSL extensions
  • Status changed from New to Resolved
  • Assignee set to Debbie Lockett
  • Applies to JS Branch Trunk added
  • Fix Committed on JS Branch Trunk added

Rather than add a new instruction, I think it is better (and easier) to update the existing syntax to enable this.

I have added a new option for the HTTP client, which allows users to specify that they want the content of a successful response to be added to one of the internal resource pools. For instance, adding 'pool':'xml' to the HTTP request map means that a successfully loaded document will be added to the documentPool, making it available to a document() call.

Updates committed on the main (SaxonJS3) branch:

  • implementation in Fetch.js (httpRequestPromise and prepareRequest)
  • tests added: in nodejs/schedule (for ixsl:schedule-action/@http-request); in nodejs/schedule-v3 (for ixsl:promise and ixsl:http-request()); browser/iss6355 (for ixsl:promise and ixsl:http-request())
  • documentation update in development/http section

Please register to edit this issue

Also available in: Atom PDF Tracking page