|
Subject: Re: [xsl] How to call an XSLT function whose name isn't known till run-time? From: "Dimitre Novatchev dnovatchev@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> Date: Sat, 7 Dec 2019 17:04:14 -0000 |
Thank you, Dr. Kay,
>
> This can be simplified to:
>
> <xsl:variable name="vFuns" as="map(xs:string, function(*))"
> select="map {
> 'move' : f:move#0,
> 'stop' : f:stop#0
> }
> "
> />
>
Yes, I know the f:fun#Arity syntax but could never force myself to use
it -- still seems rather "unnatural".
As for:
> <xsl:map>
> <xsl:map-entry key="'move'" select="f:move#0"/>
> <xsl:map-entry key="'stop'" select="f:stop#0"/>
> </xsl:map>
this seems of little use as the <xsl:map> instruction has to be
enclosed in the body of an <xsl:variable> -- so isn't it better just
to define the map in the `select` attribute of the variable
declaration?
Also, why use the verbose <xsl:map-entry> as compared to the XPath way
of writing a map-literal? I know that this can be useful in
dynamically creating a map when the number of key-value pairs is
determined at runtime -- but this still isn't the case in this
question.
Cheers,
Dimitre
On Sat, Dec 7, 2019 at 12:59 AM Michael Kay mike@xxxxxxxxxxxx
<xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote:
>
> 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"
> 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@xxxxxxxxx
<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
> EasyUnsubscribe (by email)
>
>
> XSL-List info and archive
> EasyUnsubscribe (by email)
--
Cheers,
Dimitre Novatchev
---------------------------------------
Truly great madness cannot be achieved without significant intelligence.
---------------------------------------
To invent, you need a good imagination and a pile of junk
-------------------------------------
Never fight an inanimate object
-------------------------------------
To avoid situations in which you might make mistakes may be the
biggest mistake of all
------------------------------------
Quality means doing it right when no one is looking.
-------------------------------------
You've achieved success in your field when you don't know whether what
you're doing is work or play
-------------------------------------
To achieve the impossible dream, try going to sleep.
-------------------------------------
Facts do not cease to exist because they are ignored.
-------------------------------------
Typing monkeys will write all Shakespeare's works in 200yrs.Will they
write all patents, too? :)
-------------------------------------
Sanity is madness put to good use.
-------------------------------------
I finally figured out the only reason to be alive is to enjoy it.
| Current Thread |
|---|
|
| <- Previous | Index | Next -> |
|---|---|---|
| Re: [xsl] How to call an XSLT funct, Michael Kay mike@xxx | Thread | Re: [xsl] How to call an XSLT funct, Michael Kay mike@xxx |
| Re: [xsl] How to call an XSLT funct, Michael Kay mike@xxx | Date | [xsl] URI collection select?, dvint@xxxxxxxxx |
| Month |