Vishal,

Xalan in the JDK is a compiler (XSLTC) and as such it tries to resolve as much as it can statically. As a result, there are some limitations. The discussion and resolution in [1] may help.

-- Santiago

[1] http://issues.apache.org/jira/browse/XALANJ-1485

On Nov 2, 2009, at 7:21 AM, Javalkar, Vishal wrote:

Hi,

Apparently, Xalan (the one bundled with JDK 6 at-least) complains when a java.util.Map is passed as a parameter to an XSLT stylesheet.

Assuming, I have a snippet of code as:

Map inputparam = new HashMap(); 
inputparam.put("greeting", "hi there");
transformer.setParameter("inputparam", inputparam);
...
transformer.transform(...);

and I have a simple XSLT that attempts to get the key 'greeting' from 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.HashMap"
        extension-element-prefixes="map">
        
        <xsl:param name="inputparam" />
        
        <xsl:template match="/">
                <xsl:variable name="greeting"
                        select="map:get($inputparam, 'greeting')" />
                <greeting><xsl:value-of select="greeting"/></greeting>          
    
        </xsl:template>
</xsl:stylesheet>

I obtain the following error:

ERROR: 'Cannot find external method 'java.util.HashMap.get' (must be public).'
FATAL ERROR:  'Could not compile stylesheet'
javax.xml.transform.TransformerConfigurationException: Could not compile stylesheet at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl.newTemplates (TransformerFactoryImpl.java:825) at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl.newTransformer (TransformerFactoryImpl.java:614)
        at xalanxslttest.ExecuteXslt.main(ExecuteXslt.java:36)


Is there a way to solve this? Is this supported?

All help/advice appreciated!
Thanks & Regards,
Vishal


Reply via email to