[xsl] getting result documents out of a function that calls transform()

Subject: [xsl] getting result documents out of a function that calls transform()
From: "Graydon graydon@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Wed, 31 Mar 2021 18:25:07 -0000
In the interest of doing a bunch of small named transformations in a
particular order (for refactoring, or to regularize content before
processing it generally), I have this function:


<xsl:function name="local:processList" as="document-node()">
    <xsl:param as="document-node()" name="initial" />
    <xsl:param as="xs:string*" name="list" />

    <xsl:choose>
      <xsl:when test="not(exists($list))">
        <xsl:sequence select="$initial" />
      </xsl:when>
      <xsl:otherwise>
        <xsl:sequence select="
            local:processList(
              transform(
                map:merge(($transformMap(head($list)),
                map:entry('source-node', $initial))
                )
              )?output, tail($list)
            )" />
      </xsl:otherwise>
    </xsl:choose>
  </xsl:function>

The function works fine; given an initial document, a list of named
transformation events, and a map between transformation even names and
maps of transform() paramters:

<xsl:map>
  <xsl:map-entry key="'first'">
    <xsl:map>
      <xsl:map-entry key="'stylesheet-location'" select="'one.xsl'" />
      <xsl:map-entry key="'stylesheet-params'">
        <xsl:map>
          <xsl:map-entry key="QName('', 'debugPath')" select="concat($diagnosticPath, '/first.xml')" />
        </xsl:map>
      </xsl:map-entry>
      <xsl:map-entry key="'static-params'">
        <xsl:map>
          <xsl:map-entry key="QName('', 'DEBUG')" select="$DEBUG" />
        </xsl:map>
      </xsl:map-entry>
    </xsl:map>
  </xsl:map-entry>
  b&
</xsl:map>

(and the actual individual transform xsl documents), it does the thing
and performs each of the transforms in the expected order.  I can get
$DEBUG into the transform function call, so in principle
xsl:result-document is being called when $DEBUG is true to return
whatever document the individual XSL transform produced.

How do I get those DEBUG result documents back out of the function?

The only approach I can think of is to add an argument to the function
and have that accumulate the full return maps from calls to transform()
and to pass that back when the function completes.  This feels like it
lacks elegance.

Is there a better way?

Thanks!

-- 
Graydon Saunders  | graydonish@xxxxxxxxx
CC&s oferC)ode, C0isses swC! mC&g.
-- Deor  ("That passed, so may this.")

Current Thread