Re: [xsl] Using saxon-js to run a javasscript function from XSLT at the command line

Subject: Re: [xsl] Using saxon-js to run a javasscript function from XSLT at the command line
From: "Martynas Jusevičius martynas@xxxxxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Tue, 20 May 2025 19:14:23 -0000
This works (tested in https://martin-honnen.github.io/xslt3fiddle/),
but the JS function is inlined in the stylesheet.
Maybe you could use unparsed-text() to get the contents of the JS
file, and then ixsl:eval() them.

<?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";
  exclude-result-prefixes="#all"
  xmlns:ixsl="http://saxonica.com/ns/interactiveXSLT";
  xmlns:mf="http://example.org/my-functions";
  expand-text="yes">

  <xsl:mode on-no-match="shallow-copy"/>

  <xsl:template match="/" name="xsl:initial-template">
    <xsl:value-of select="mf:greet('World')"/>
  </xsl:template>

   <xsl:function name="mf:greet" as="xs:string">
    <xsl:param name="name" as="xs:string"/>

    <xsl:variable name="js-statement" as="xs:string" expand-text="no">
      <![CDATA[
      function greet(name) {
         return "Hello\, " + name + "!";
      }
      ]]>
    </xsl:variable>
    <xsl:variable name="js-function"
select="ixsl:eval(normalize-space($js-statement))"/>
    <xsl:sequence select="ixsl:apply($js-function, [ $name ])"/>
  </xsl:function>

</xsl:stylesheet>

On Tue, May 20, 2025 at 8:07b/PM Liam R. E. Quin liam@xxxxxxxxxxxxxxxx
<xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote:
>
> On Tue, 2025-05-20 at 17:46 +0000, dvint dvint@xxxxxxxxx wrote:
> > Based upon Michael Kay's response it is not possible to do this
> > without having the Javascript drive the process.
>
> One way might be to set up your node-based JS application to listen on
> localhost, and use wget or curl on the command-line to fetch its
> result.
>
> liam
>
> --
> Liam Quin, https://www.delightfulcomputing.com/
>
> XSLT Foundations course in June, see delightfulcomputing.com

Current Thread