xsl:map
Used to construct a new map.
Category: instruction
Content: sequence-constructor
Permitted parent elements:
any XSLT element whose content model is
sequence-constructor; any literal result element
Attributes
|
| New in XSLT 4.0. Provides an alternative way of supplying the input sequence for constructing the map; if present, the contained sequence constructor must be empty. |
|
| New in XSLT 4.0. An expression which must
evaluate to either one of the strings |
Saxon availability
Available in XSLT 3.0 and later versions. From Saxon 9.8, available in all editions. Implemented in Saxon-PE and Saxon-EE since Saxon 9.6. Available for all platforms.
Notes on the Saxon implementation
The new attributes duplicates and select
are available from Saxon 13 in XSLT 4.0. The 4.0
duplicates attribute replaces on-duplicates which
was defined in earlier drafts, and which was based on the Saxon extension
attribute saxon:on-duplicates, which were previously available in
Saxon 10 to 12, and are now dropped.
Details
The sequence constructor must evaluate to a sequence of maps. These can be constructed using xsl:map-entry elements.
Examples
Example 1
<xsl:variable name="week" as="map(xs:string, xs:string)"> <xsl:map> <xsl:map-entry key="'Mo'" select="'Monday'"/> <xsl:map-entry key="'Tu'" select="'Tuesday'"/> <xsl:map-entry key="'We'" select="'Wednesday'"/> <xsl:map-entry key="'Th'" select="'Thursday'"/> <xsl:map-entry key="'Fr'" select="'Friday'"/> <xsl:map-entry key="'Sa'" select="'Saturday'"/> <xsl:map-entry key="'Su'" select="'Sunday'"/> </xsl:map> </xsl:variable>
Example 2
This XSLT 4.0 example creates a map in which the value for a given product code is the total of the sales for that product across multiple outlets.
<xsl:variable name="total-sales-by-sku" as="map(xs:string, xs:decimal)"> <xsl:map duplicates="fn($old, $new){$old + $new}"> <xsl:for-each select="//outlet/product"> <xsl:map-entry key="@sku" select="xs:decimal(@sales)"/> </xsl:for-each> </xsl:map> </xsl:variable>