Is it possible to embed a function inside a map (for example) by value e.g.
<xsl:function name="kooks:stringAdd" as="xs:string">
<xsl:param name="s1" as="xs:string"/>
<xsl:param name="s2" as="xs:string"/>
<xsl:sequence select="concat($s1,$s2)"/>
</xsl:function>
<xsl:variable name="stringMonoid" as="map(*)">
<xsl:map>
<xsl:map-entry key="'zero'" select="''" as="xs:string"/>
<xsl:map-entry key="'add'" select="kooks:stringAdd#2"/>
</xsl:map>
</xsl:variable>
can i write it (in psuedo xslt) like this.
<xsl:variable name="stringMonoid" as="map(*)">
<xsl:map>
<xsl:map-entry key="'zero'" select="''" as="xs:string"/>
<xsl:map-entry key="'add'">
<xsl:function as="xs:string">
<xsl:param name="s1" as="xs:string"/>
<xsl:param name="s2" as="xs:string"/>
<xsl:sequence select="concat($s1,$s2)"/>
</xsl:function>
</xsl:map>
</xsl:map>
</xsl:variable>
Clarification, the question is about XSLT functions, I want to be able to construct and return elements (sadly the example returns atomic types), and whilst you can embed xpath expressions that contain inline functions, I'm not sure these can construct elements.
You can use an anonymous function/lambda expression as a key value e.g.
outputs something like (the processor and date info will vary)
Example fiddle using SaxonC HE 12.3.
If you want to create the map with
xsl:map
thenis possible for an anonymous function (created with XPath, admittedly). But it is not clear to me why you would want to use XSLT to create an anonymous function, if your first example has a named function defined with
xsl:function
, why doesn't that suffice?