Re: referencing a map produced from a function

Alan Painter <[email protected]> Tue, 27 Oct 2020 17:30:45 +0100
Newsgroups gmane.text.xml.saxon.help
Message-ID <CAN+GtW0fiL_tx1S4Z8oru9JcSN7o6-cBzzo0vwZZ4sgQTvrpqQ@mail.gmail.com>
This works for me:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  version="3.0"
  xmlns:xs="http://www.w3.org/2001/XMLSchema"
  exclude-result-prefixes="#all"
  expand-text="yes"
  xmlns:local="local:functions">

  <xsl:template name="xsl:initial-template">
      <output>{*local:createMap('city')('Boston')*}</output>
  </xsl:template>

  <xsl:function name="local:createMap" as="map(xs:string, item())" >
    <xsl:param name="type" as="xs:string" />

    <xsl:choose>
      <xsl:when test="$type eq 'city'">
        <xsl:sequence select="$cityMap" />
      </xsl:when>
      <xsl:otherwise>
        <xsl:sequence select="map {}" />
      </xsl:otherwise>
    </xsl:choose>

  </xsl:function>

  <xsl:variable name="cityMap" as="map(xs:string, xs:string)"
                select="map { 'Boston' : 'Massachusetts',
                              'Paris'  :  'France'
                            }" />

</xsl:stylesheet>

On Tue, Oct 27, 2020 at 5:21 PM Gunther Rademacher <[email protected]> wrote:

> It would be a dynamic function invocation
> <https://www.w3.org/TR/xquery-31/#id-dynamic-function-invocation> which
> consists on a (primary) expression, followed by an argument list. A dollar
> sign is only ever used to introduce a variable name.
>
> Or is it
>
> $local:createMap($typeOfMap)($param)
>
> On Tue, Oct 27, 2020 at 12:02 PM Alan Painter <[email protected]>
> wrote:
>
>> Isn't that simply:
>>
>> local:createMap($typeOfMap)($param)  ?
>>
>> On Tue, Oct 27, 2020, 16:53 Ihe Onwuka <[email protected]> wrote:
>>
>>> A variable called a that contains a map can be referenced as $a and you
>>> can simulate a map:get with with the function call $a($keyValue).
>>>
>>> Suppose the map was instead created by a function that takes a parameter
>>> that determines what kind of map to create.
>>>
>>>  So local:createMap($typeOfMap) returns a map. Do we know have use the
>>> explicit map:get form, if not what does the function call form look like.
>>> _______________________________________________
>>> saxon-help mailing list archived at http://saxon.markmail.org/
>>> [email protected]
>>> https://lists.sourceforge.net/lists/listinfo/saxon-help
>>
>> _______________________________________________ saxon-help mailing list
> archived at http://saxon.markmail.org/ [email protected]
> https://lists.sourceforge.net/lists/listinfo/saxon-help
> _______________________________________________
> saxon-help mailing list archived at http://saxon.markmail.org/
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/saxon-help

_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
[email protected]
https://lists.sourceforge.net/lists/listinfo/saxon-help