I also like this XSLT/XPath 3 way:
<xsl:stylesheet version="3.0" xmlns:xsl="
http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:f="my:f">
<xsl:param name="pFunName" select="'move'" as="xs:string"/>
<xsl:variable name="vFuns" as="map(xs:string, function(*))"
select="map {
'move' : function() as xs:string {f:move()},
'stop' : function() as xs:string {f:stop()}
}
"
/>
<xsl:function name="f:move" as="xs:string">
Move
</xsl:function>
<xsl:function name="f:stop" as="xs:string">
Stop
</xsl:function>
<xsl:template match="/">
<xsl:value-of select="$vFuns('move')(), $vFuns('stop')()"/>
</xsl:template>
</xsl:stylesheet>
In this line of the code:
<xsl:value-of select="$vFuns('move')(), $vFuns('stop')()"/>
we can also pass string variables or expressions that produce string and
not just the literal name of the function.
When this simple example is run (against any XML document -- not used), we
get the expected result:
Move
Stop
Cheers,
Dimitre
On Fri, Dec 6, 2019 at 9:20 AM Costello, Roger L. costello(_at_)mitre(_dot_)org
<
xsl-list-service(_at_)lists(_dot_)mulberrytech(_dot_)com> wrote:
Hi Folks,
I have an XSLT variable, $function-to-invoke, that holds the name of an
XSLT function to be invoked. For example, if $function-to-invoke holds the
string "move" then I want my XSLT program to invoke the function with that
name, i.e., invoke f:move(...). Is there a way for XSLT to call a function
whose name isn't known till run-time?
/Roger
--~----------------------------------------------------------------
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
--~--