xsl:map
Constructs an XPath 3.1 map from a sequence of xsl:map-entry children.
<xsl:map>
<xsl:map-entry key="'name'" select="'Patrick'"/>
<xsl:map-entry key="'age'" select="42"/>
</xsl:map>xsl:map is the construction counterpart to the XPath map{} literal — useful when keys or values come from XSLT instructions that can’t easily be expressed inline. Each xsl:map-entry contributes one key-value pair. Duplicate keys cause a dynamic error unless allowed by configuration.
xsl:map-entry attributes
| Attribute | Description |
|---|---|
key |
XPath expression for the entry key. Required. |
select |
XPath expression for the entry value. |
If select is absent, the body of xsl:map-entry (a sequence constructor) provides the value.
Example
Building a lookup table from input data:
<xsl:variable name="prices" as="map(*)">
<xsl:map>
<xsl:for-each select="product">
<xsl:map-entry key="@id" select="@price"/>
</xsl:for-each>
</xsl:map>
</xsl:variable>
<xsl:value-of select="$prices('A-100')"/>