Subject: Re: [xsl] How to call an XSLT function whose name isn't known till run-time? From: "Michael Kay mike@xxxxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> Date: Sat, 7 Dec 2019 08:59:19 -0000 |
This can be simplified to: > <xsl:variable name="vFuns" as="map(xs:string, function(*))" > select="map { > 'move' : f:move#0, > 'stop' : f:stop#0 > } > " > /> You can also use XSLT syntax: <xsl:map> <xsl:map-entry key="'move'" select="f:move#0"/> <xsl:map-entry key="'stop'" select="f:stop#0"/> </xsl:map> > On 7 Dec 2019, at 01:45, Dimitre Novatchev dnovatchev@xxxxxxxxx <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote: > > I also like this XSLT/XPath 3 way: > > <xsl:stylesheet version="3.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform <http://www.w3.org/1999/XSL/Transform>" > xmlns:xs="http://www.w3.org/2001/XMLSchema <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@xxxxxxxxx <mailto:costello@xxxxxxxxx> <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx <mailto:xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>> 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/293509> (by email <>)
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] How to call an XSLT funct, Dimitre Novatchev dn | Thread | Re: [xsl] How to call an XSLT funct, Dimitre Novatchev dn |
Re: [xsl] How to call an XSLT funct, Dimitre Novatchev dn | Date | Re: [xsl] How to call an XSLT funct, Dimitre Novatchev dn |
Month |