Problem accessing hashmap in XSL

Assuming I have a piece of code like:

 Map mappingId = new HashMap();
 mappingId.put("1", "1000");
 transformer.setParameter("mappingId", mappingId);

 transformer.transform(...);

and I have a simple XSLT that tries to get the key to this

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
xmlns:map="xalan://java.util.Map"
extension-element-prefixes="map">

<xsl:param name="mappingId" />

<xsl:template match="/">
<xsl:variable name="id" select="map:get($mappingId, '1')" />
<MappedId><xsl:value-of select="id"/></MappedId>

</xsl:template>
</xsl:stylesheet>

I get the following error:

ERROR: 'could not find method java.util.Map.get ([ExpressionContext,] #STRING, #STRING) FATAL ERROR: "Could not compile stylesheet".

Can anyone help me find out how to access a java map in XSL?

+3
source share
1 answer

The id parameter should be available by adding $. The following XSL seems to give the expected result for me (java 1.6).

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:map="xalan://java.util.Map" extension-element-prefixes="map">

    <xsl:param name="mappingId" />

    <xsl:template match="/">
        <xsl:variable name="id" select="map:get($mappingId, '1')" />
        <MappedId>
            <xsl:value-of select="$id" />
        </MappedId>

    </xsl:template>
</xsl:stylesheet>

Conclusion:

<?xml version="1.0" encoding="UTF-8"?>
<MappedId>1000</MappedId>
0
source

All Articles