Re: Passing a "callback" name to ixsl:schedule-action
Martynas Jusevičius <martynas-tyFqBaoSXPC1Z/[email protected]>
| Newsgroups | gmane.text.xml.saxon.help |
|---|---|
| Message-ID | <CAE35VmxhQCpdop__f+BbdRQVzUr23rE5ePXy01aYubYDj+LHAQ@mail.gmail.com> |
Thanks. I'm not yet familiar with higher-order functions in XSLT. Lets say I want to use <xsl:function name="apl:resource-typeahead-callback"> as the callback -- how do I supply it as $callback? On Fri, Aug 28, 2020 at 11:23 AM Michael Kay <[email protected]> wrote: > > This is very much in the whole area of my Balisage 2020 paper an Asynchronous XSLT, and of course that describes the limitations of the current design which this use case illustrates well. > > You're constrained to invoke a statically-known template within ixsl:schedule-action, but the parameters to that template can include a function item which is invoked dynamically. So you can do something like > > <ixsl:schedule-action http-request="...."> > <xsl:call-template name="http-completion"> > <xsl:with-param name="action" as="function(*)" select="$callback"/> > </xsl:call-template> > </ixsl:schedule-action> > > <xsl:template name="http-completion"> > <xsl:param name="action" as="function(*)"/> > <xsl:sequence select="$action()"/> > </xsl:template> > > Michael Kay > Saxonica > > On 28 Aug 2020, at 10:13, Martynas Jusevičius <[email protected]> wrote: > > Hi, > > with Saxon-CE I've used a typeahead "library" which would accept both > the JS function to be called and the callback as params: > > <!-- caller --> > > <xsl:call-template name="typeahead:load-xml"> > <xsl:with-param name="element" select="."/> > <xsl:with-param name="query" select="$text"/> > <xsl:with-param name="uri" select="$results-uri"/> > <xsl:with-param name="js-function" select="$js-function"/> > <xsl:with-param name="callback" select="ixsl:get(ixsl:window(), > 'onresourceTypeaheadCallback')"/> > </xsl:call-template> > > <!-- library --> > > <xsl:template name="typeahead:load-xml"> > <xsl:param name="element" as="element()"/> > <xsl:param name="uri" as="xs:anyURI"/> > <xsl:param name="query" as="xs:string"/> > <xsl:param name="js-function" as="xs:string"/> > <xsl:param name="callback"/> > <!-- if the value hasn't changed during the delay --> > <xsl:if test="$query = $element/ixsl:get(., 'value')"> > <xsl:value-of select="ixsl:call(ixsl:window(), $js-function, [ > ixsl:event(), $uri, $callback ])"/> > </xsl:if> > </xsl:template> > > Now I want to replace all custom HTTP-related functions with > <ixsl:schedule-action http-request="">. So I picture something like > this: > > <xsl:template name="typeahead:load-xml"> > <xsl:param name="element" as="element()"/> > <xsl:param name="uri" as="xs:anyURI"/> > <xsl:param name="query" as="xs:string"/> > <!-- if the value hasn't changed during the delay --> > <xsl:if test="$query = $element/ixsl:get(., 'value')"> > <xsl:schedule-action http-request="map{ 'method': 'GET', > 'href': $uri, 'headers': map{ 'Accept': 'application/rdf+xml' } }"> > <xsl:call-template name="?????????"/> > </ixsl:schedule action> > </xsl:if> > </xsl:template> > > So <xsl:call-template> functions like a callback here, but I cannot > pass template name as a param. Of course I could hardcode some name > like "typeahead:xml-loaded", but I would prefer not doing that. > > Is there an idiomatic Saxon-JS solution to this? > > > _______________________________________________ > saxon-help mailing list archived at http://saxon.markmail.org/ > [email protected] > https://lists.sourceforge.net/lists/listinfo/saxon-help > > > _______________________________________________ > saxon-help mailing list archived at http://saxon.markmail.org/ > [email protected] > https://lists.sourceforge.net/lists/listinfo/saxon-help _______________________________________________ saxon-help mailing list archived at http://saxon.markmail.org/ [email protected] https://lists.sourceforge.net/lists/listinfo/saxon-help