Re: passing a function as a parameter to transform()

"Michael Kay [email protected]" <[email protected]> Fri, 14 May 2021 13:05:31 -0000
Newsgroups gmane.text.xml.xsl.general.mulberrytech
Message-ID <[email protected]>
You're calling <xsl:sequence select=3D"local:tiny('away')" />, but there is=
 no function named local:tiny in scope. What there is is a variable (parame=
ter) named local:tiny, whose value is a function. So you need a dynamic cal=
l on the function held in the variable, not a static call on a function nam=
ed local:tiny(). That is, you need=20

<xsl:sequence select=3D"$local:tiny('away')" />

Michael Kay
Saxonica

> On 14 May 2021, at 13:15, Graydon [email protected] <xsl-list-service@lis=
ts.mulberrytech.com> wrote:
>=20
> On Thu, May 13, 2021 at 09:20:49PM -0000, Michael Kay [email protected] s=
cripsit:
>> To pass the function itself, rather than the result of a function call, =
use local:getString#2.
>=20
> Thank you!
>=20
> That moves the error into the stylesheet called by transform():
>=20
> Engine name: Saxon-EE 10.3 (External)
> Severity: error
> Description: Cannot find a 1-argument function named Q{data:,dpc}tiny()
>=20
> The tiny test example has an "outer" stylesheet:
>=20
> <?xml version=3D"1.0" encoding=3D"UTF-8"?>
> <xsl:stylesheet xmlns:xsl=3D"http://www.w3.org/1999/XSL/Transform"
>  xmlns:xs=3D"http://www.w3.org/2001/XMLSchema"
>  xmlns:math=3D"http://www.w3.org/2005/xpath-functions/math"
>  xmlns:xd=3D"http://www.oxygenxml.com/ns/doc/xsl"
>  xmlns:local=3D"data:,dpc"
>  exclude-result-prefixes=3D"xs math xd local"
>  version=3D"3.0">
>  <xd:doc scope=3D"stylesheet">
>    <xd:desc>
>      <xd:p><xd:b>Created on:</xd:b> May 13, 2021</xd:p>
>      <xd:p><xd:b>Author:</xd:b> graydon</xd:p>
>      <xd:p>pass a function to a transform() call</xd:p>
>    </xd:desc>
>  </xd:doc>
>  <xd:doc>
>    <xd:desc>minimalist function</xd:desc>
>    <xd:param name=3D"in">whatever string we're called with</xd:param>
>  </xd:doc>
>  <xsl:function name=3D"local:tiny" as=3D"text()">
>    <xsl:param name=3D"in" as=3D"xs:string" />
>    <xsl:value-of select=3D"$in" />
>  </xsl:function>
>=20
>  <!-- test content -->
>  <xsl:variable name=3D"consume" as=3D"document-node()">
>    <xsl:document>
>      <stuff>
>        <goes>
>          <here>Around the words</here>
>        </goes>
>      </stuff>
>    </xsl:document>
>  </xsl:variable>
>=20
>  <xd:doc>
>    <xd:desc>do the thing</xd:desc>
>  </xd:doc>
>  <xsl:template name=3D"xsl:initial-template">
>    <xsl:variable name=3D"testResult">
>      <xsl:sequence select=3D"
>          transform(map {
>            'stylesheet-location': 'functionTest.xsl',
>            'source-node': $consume,
>            'stylesheet-params': map {
>              QName('local', 'tiny'): local:tiny#1
>            }
>          })?output" />
>    </xsl:variable>
>    <xsl:sequence select=3D"$testResult" />
>  </xsl:template>
> </xsl:stylesheet>
>=20
> calling
>=20
> <?xml version=3D"1.0" encoding=3D"UTF-8"?>
> <xsl:stylesheet xmlns:xsl=3D"http://www.w3.org/1999/XSL/Transform"
>  xmlns:xs=3D"http://www.w3.org/2001/XMLSchema"
>  xmlns:math=3D"http://www.w3.org/2005/xpath-functions/math"
>  xmlns:xd=3D"http://www.oxygenxml.com/ns/doc/xsl"
>  xmlns:local=3D"data:,dpc"
>  exclude-result-prefixes=3D"xs math xd local"
>  version=3D"3.0">
>  <xd:doc scope=3D"stylesheet">
>    <xd:desc>
>      <xd:p><xd:b>Created on:</xd:b> May 13, 2021</xd:p>
>      <xd:p><xd:b>Author:</xd:b> graydon</xd:p>
>      <xd:p></xd:p>
>    </xd:desc>
>  </xd:doc>
>  <xsl:param name=3D"local:tiny" as=3D"function(xs:string) as text()" />
>=20
>  <xsl:mode on-no-match=3D"shallow-copy"/>
>=20
>  <xd:doc>
>    <xd:desc>this is the test case</xd:desc>
>  </xd:doc>
>  <xsl:template match=3D"goes">
>    <xsl:copy>
>      <xsl:sequence select=3D"local:tiny('away')" />
>    </xsl:copy>
>  </xsl:template>
> </xsl:stylesheet>
>=20
> presumably I have not set the parameter up correctly to be recognized as
> a function in the stylesheet being called by transform(), but I'm
> finding myself at a loss as to how not.
>=20
> What am I doing wrong, here?
>=20
> Thanks!
>=20
> --=20
> Graydon Saunders  | [email protected]
> =C3=9E=C3=A6s ofer=C3=A9ode, =C3=B0isses sw=C3=A1 m=C3=A6g.
> -- Deor  ("That passed, so may this.")
>=20
>=20
--~----------------------------------------------------------------
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]
--~--