[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: getting result documents out of a function that ca

Subject: Re: getting result documents out of a function that calls transform()
From: "Graydon graydon@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Thu, 1 Apr 2021 14:45:35 -0000
Re:  getting result documents out of a function that ca
On Wed, Mar 31, 2021 at 06:46:05PM -0000, Liam R. E. Quin liam@xxxxxxxxxxxxxxxx scripsit:
> On Wed, 2021-03-31 at 18:26 +0000, Graydon graydon@xxxxxxxxx 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  | graydonish@xxxxxxxxx
^fs oferiode, pisses swa mfg.
-- Deor  ("That passed, so may this.")

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.