Re: getting result documents out of a function that calls transform()

"Graydon [email protected]" <[email protected]> Thu, 1 Apr 2021 14:45:43 -0000
Newsgroups gmane.text.xml.xsl.general.mulberrytech
Message-ID <[email protected]>
On Wed, Mar 31, 2021 at 06:46:05PM -0000, Liam R. E. Quin [email protected] scripsit:
> On Wed, 2021-03-31 at 18:26 +0000, Graydon [email protected] wrote:
> > How do I get those DEBUG result documents back out of the function?
> 
> You probably do need to have your function take a map as an argument.
> A sequence of "documents-so-far" is even less elegant when you start
> dealing with where to write them out to.

For posterity:

<xd:doc>
    <xd:desc>process transformation events in list order with fetched params</xd:desc>
    <xd:param name="initial">the document we're going to transform</xd:param>
    <xd:param name="list">the list of transformation event names we need to process</xd:param>
    <xd:param name="results">the accumulating return values of the successive transform() calls</xd:param>
</xd:doc>
<xsl:function name="local:processList" as="map(*)">
  <xsl:param as="document-node()" name="initial" />
  <xsl:param as="xs:string*" name="list" />
  <xsl:param as="map(*)" name="results" />

  <xsl:choose>
    <xsl:when test="not(exists($list))">
      <!-- no more event names to process, so stop and return what we were called with -->
      <xsl:sequence select="map:merge((map:entry('processed',$initial),$results))" />
    </xsl:when>
    <xsl:otherwise>
      <!-- we still have events to process -->
      <xsl:variable name="temp" as="map(*)" select="transform(
              map:merge(
              ($transformMap(head($list)),
              map:entry('source-node', $initial))
              )
            )"/>
      <!-- when we add this transform result, remove the output key because that will duplicate -->
      <xsl:sequence select="
          local:processList($temp?output,tail($list),map:merge(($results,map:remove($temp,'output')))
          )" />
    </xsl:otherwise>
  </xsl:choose>
</xsl:function>


Not elegant, but functional.

I think it would be helpful for map:merge() to throw a warning if the
second argument doesn't contain any recognizable option names.

Thanks!

-- 
Graydon Saunders  | [email protected]
Þæs oferéode, ðisses swá mæg.
-- Deor  ("That passed, so may this.")
--~----------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
EasyUnsubscribe: http://lists.mulberrytech.com/unsub/xsl-list/3329386
or by email: [email protected]
--~--