xsl-list
[Top] [All Lists]

Re: [xsl] passing a function as a parameter to transform()

2021-05-14 08:05:32
You're calling <xsl:sequence select="local:tiny('away')" />, but there is no 
function named local:tiny in scope. What there is is a variable (parameter) 
named local:tiny, whose value is a function. So you need a dynamic call on the 
function held in the variable, not a static call on a function named 
local:tiny(). That is, you need 

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

Michael Kay
Saxonica

On 14 May 2021, at 13:15, Graydon graydon(_at_)marost(_dot_)ca 
<xsl-list-service(_at_)lists(_dot_)mulberrytech(_dot_)com> wrote:

On Thu, May 13, 2021 at 09:20:49PM -0000, Michael Kay 
mike(_at_)saxonica(_dot_)com scripsit:
To pass the function itself, rather than the result of a function call, use 
local:getString#2.

Thank you!

That moves the error into the stylesheet called by transform():

Engine name: Saxon-EE 10.3 (External)
Severity: error
Description: Cannot find a 1-argument function named Q{data:,dpc}tiny()

The tiny test example has an "outer" stylesheet:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
 xmlns:xs="http://www.w3.org/2001/XMLSchema";
 xmlns:math="http://www.w3.org/2005/xpath-functions/math";
 xmlns:xd="http://www.oxygenxml.com/ns/doc/xsl";
 xmlns:local="data:,dpc"
 exclude-result-prefixes="xs math xd local"
 version="3.0">
 <xd:doc scope="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="in">whatever string we're called with</xd:param>
 </xd:doc>
 <xsl:function name="local:tiny" as="text()">
   <xsl:param name="in" as="xs:string" />
   <xsl:value-of select="$in" />
 </xsl:function>

 <!-- test content -->
 <xsl:variable name="consume" as="document-node()">
   <xsl:document>
     <stuff>
       <goes>
         <here>Around the words</here>
       </goes>
     </stuff>
   </xsl:document>
 </xsl:variable>

 <xd:doc>
   <xd:desc>do the thing</xd:desc>
 </xd:doc>
 <xsl:template name="xsl:initial-template">
   <xsl:variable name="testResult">
     <xsl:sequence select="
         transform(map {
           'stylesheet-location': 'functionTest.xsl',
           'source-node': $consume,
           'stylesheet-params': map {
             QName('local', 'tiny'): local:tiny#1
           }
         })?output" />
   </xsl:variable>
   <xsl:sequence select="$testResult" />
 </xsl:template>
</xsl:stylesheet>

calling

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
 xmlns:xs="http://www.w3.org/2001/XMLSchema";
 xmlns:math="http://www.w3.org/2005/xpath-functions/math";
 xmlns:xd="http://www.oxygenxml.com/ns/doc/xsl";
 xmlns:local="data:,dpc"
 exclude-result-prefixes="xs math xd local"
 version="3.0">
 <xd:doc scope="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="local:tiny" as="function(xs:string) as text()" />

 <xsl:mode on-no-match="shallow-copy"/>

 <xd:doc>
   <xd:desc>this is the test case</xd:desc>
 </xd:doc>
 <xsl:template match="goes">
   <xsl:copy>
     <xsl:sequence select="local:tiny('away')" />
   </xsl:copy>
 </xsl:template>
</xsl:stylesheet>

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.

What am I doing wrong, here?

Thanks!

-- 
Graydon Saunders  | graydonish(_at_)gmail(_dot_)com
Þæ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/1167547
or by email: xsl-list-unsub(_at_)lists(_dot_)mulberrytech(_dot_)com
--~--


<Prev in Thread] Current Thread [Next in Thread>