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

"Martin Honnen [email protected]" <[email protected]> Fri, 14 May 2021 12:20:05 -0000
Newsgroups gmane.text.xml.xsl.general.mulberrytech
Message-ID <[email protected]>
<html>
 <head>
  <meta name=3D"viewport" content=3D"width=3Ddevice-width">
  <meta http-equiv=3D"Content-Type" content=3D"text/vnd.ui.insecure+html;ch=
arset=3Dutf-8">
 </head>
 <body style=3D"overflow-wrap:break-word; word-break: break-word;"><div cla=
ss=3D"mail_android_message" style=3D"line-height: 1; padding: 0.5em">Perhap=
s try visibility=3D&quot;public&quot; on the function declaration <br/><br/=
>--<br/>Diese Nachricht wurde von meinem Android Mobiltelefon mit GMX Mail =
gesendet.</div><div class=3D"mail_android_quote" style=3D"line-height: 1; p=
adding: 0.3em"><html><body>Am 14.05.21, 14:15 schrieb &quot;Graydon graydon=
@marost.ca&quot; &lt;[email protected]&gt;:</body></h=
tml><blockquote class=3D"gmail_quote" style=3D"margin: 0.8ex 0pt 0pt 0.8ex;=
 border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">

  On Thu, May 13, 2021 at 09:20:49PM -0000, Michael Kay [email protected] s=
cripsit:
  <br> &gt; To pass the function itself, rather than the result of a functi=
on call, use local:getString#2.
  <br>=20
  <br> Thank you!
  <br>=20
  <br> That moves the error into the stylesheet called by transform():
  <br>=20
  <br> Engine name: Saxon-EE 10.3 (External)
  <br> Severity: error
  <br> Description: Cannot find a 1-argument function named Q{data:,dpc}tin=
y()
  <br>=20
  <br> The tiny test example has an "outer" stylesheet:
  <br>=20
  <br> &lt;?xml version=3D"1.0" encoding=3D"UTF-8"?&gt;
  <br> &lt;xsl:stylesheet xmlns:xsl=3D"http://www.w3.org/1999/XSL/Transform"
  <br> xmlns:xs=3D"http://www.w3.org/2001/XMLSchema"
  <br> xmlns:math=3D"http://www.w3.org/2005/xpath-functions/math"
  <br> xmlns:xd=3D"http://www.oxygenxml.com/ns/doc/xsl"
  <br> xmlns:local=3D"data:,dpc"
  <br> exclude-result-prefixes=3D"xs math xd local"
  <br> version=3D"3.0"&gt;
  <br> &lt;xd:doc scope=3D"stylesheet"&gt;
  <br> &lt;xd:desc&gt;
  <br> &lt;xd:p&gt;&lt;xd:b&gt;Created on:&lt;/xd:b&gt; May 13, 2021&lt;/xd=
:p&gt;
  <br> &lt;xd:p&gt;&lt;xd:b&gt;Author:&lt;/xd:b&gt; graydon&lt;/xd:p&gt;
  <br> &lt;xd:p&gt;pass a function to a transform() call&lt;/xd:p&gt;
  <br> &lt;/xd:desc&gt;
  <br> &lt;/xd:doc&gt;
  <br> &lt;xd:doc&gt;
  <br> &lt;xd:desc&gt;minimalist function&lt;/xd:desc&gt;
  <br> &lt;xd:param name=3D"in"&gt;whatever string we're called with&lt;/xd=
:param&gt;
  <br> &lt;/xd:doc&gt;
  <br> &lt;xsl:function name=3D"local:tiny" as=3D"text()"&gt;
  <br> &lt;xsl:param name=3D"in" as=3D"xs:string" /&gt;
  <br> &lt;xsl:value-of select=3D"$in" /&gt;
  <br> &lt;/xsl:function&gt;
  <br>=20
  <br> &lt;!-- test content --&gt;
  <br> &lt;xsl:variable name=3D"consume" as=3D"document-node()"&gt;
  <br> &lt;xsl:document&gt;
  <br> &lt;stuff&gt;
  <br> &lt;goes&gt;
  <br> &lt;here&gt;Around the words&lt;/here&gt;
  <br> &lt;/goes&gt;
  <br> &lt;/stuff&gt;
  <br> &lt;/xsl:document&gt;
  <br> &lt;/xsl:variable&gt;
  <br>=20
  <br> &lt;xd:doc&gt;
  <br> &lt;xd:desc&gt;do the thing&lt;/xd:desc&gt;
  <br> &lt;/xd:doc&gt;
  <br> &lt;xsl:template name=3D"xsl:initial-template"&gt;
  <br> &lt;xsl:variable name=3D"testResult"&gt;
  <br> &lt;xsl:sequence select=3D"
  <br> transform(map {
  <br> 'stylesheet-location': 'functionTest.xsl',
  <br> 'source-node': $consume,
  <br> 'stylesheet-params': map {
  <br> QName('local', 'tiny'): local:tiny#1
  <br> }
  <br> })?output" /&gt;
  <br> &lt;/xsl:variable&gt;
  <br> &lt;xsl:sequence select=3D"$testResult" /&gt;
  <br> &lt;/xsl:template&gt;
  <br> &lt;/xsl:stylesheet&gt;
  <br>=20
  <br> calling
  <br>=20
  <br> &lt;?xml version=3D"1.0" encoding=3D"UTF-8"?&gt;
  <br> &lt;xsl:stylesheet xmlns:xsl=3D"http://www.w3.org/1999/XSL/Transform"
  <br> xmlns:xs=3D"http://www.w3.org/2001/XMLSchema"
  <br> xmlns:math=3D"http://www.w3.org/2005/xpath-functions/math"
  <br> xmlns:xd=3D"http://www.oxygenxml.com/ns/doc/xsl"
  <br> xmlns:local=3D"data:,dpc"
  <br> exclude-result-prefixes=3D"xs math xd local"
  <br> version=3D"3.0"&gt;
  <br> &lt;xd:doc scope=3D"stylesheet"&gt;
  <br> &lt;xd:desc&gt;
  <br> &lt;xd:p&gt;&lt;xd:b&gt;Created on:&lt;/xd:b&gt; May 13, 2021&lt;/xd=
:p&gt;
  <br> &lt;xd:p&gt;&lt;xd:b&gt;Author:&lt;/xd:b&gt; graydon&lt;/xd:p&gt;
  <br> &lt;xd:p&gt;&lt;/xd:p&gt;
  <br> &lt;/xd:desc&gt;
  <br> &lt;/xd:doc&gt;
  <br> &lt;xsl:param name=3D"local:tiny" as=3D"function(xs:string) as text(=
)" /&gt;
  <br>=20
  <br> &lt;xsl:mode on-no-match=3D"shallow-copy"/&gt;
  <br>=20
  <br> &lt;xd:doc&gt;
  <br> &lt;xd:desc&gt;this is the test case&lt;/xd:desc&gt;
  <br> &lt;/xd:doc&gt;
  <br> &lt;xsl:template match=3D"goes"&gt;
  <br> &lt;xsl:copy&gt;
  <br> &lt;xsl:sequence select=3D"local:tiny('away')" /&gt;
  <br> &lt;/xsl:copy&gt;
  <br> &lt;/xsl:template&gt;
  <br> &lt;/xsl:stylesheet&gt;
  <br>=20
  <br> presumably I have not set the parameter up correctly to be recognize=
d as
  <br> a function in the stylesheet being called by transform(), but I'm
  <br> finding myself at a loss as to how not.
  <br>=20
  <br> What am I doing wrong, here?
  <br>=20
  <br> Thanks!
  <br>=20
  <br> --=20
  <br> Graydon Saunders | [email protected]
  <br> =C3=9E=C3=A6s ofer=C3=A9ode, =C3=B0isses sw=C3=A1 m=C3=A6g.
  <br> -- Deor ("That passed, so may this.")
  <br>=20
  <br>=20
  <br>=20
 </blockquote></div></body>
</html>
<div><!-- begin bl.html.trailer -->
<div style=3D"border-top:1px solid black; background-color: #dddddd;
color: #888888; font-size: smaller; padding: 5px; text-align: center;
font-family: arial,verdana,arial,sans-serif; margin-top:1em; clear:
both; margin: auto">
<a href=3D"http://www.mulberrytech.com/xsl/xsl-list">
XSL-List info and archive</a>
<div style=3D"text-align:center;">
<a style=3D"color: blue;"
  href=3D"http://lists.mulberrytech.com/unsub/xsl-list/3329386"
>EasyUnsubscribe</a>
(<a style=3D"color: blue;"
href=3D"mailto:[email protected]?subject=3Dremove"
>by email</a>)
</div>
</div>
<!-- end bl.html.trailer --></div>