Project

Profile

Help

non-static java methods calls fail on params

Added by Anonymous about 16 years ago

Legacy ID: #4868592 Legacy Poster: saul simhon (saulsim)

Hi, I ma running into an issue when calling a non-static methods whith parameters. I understand that in the XSLT call, the parameter list is supposed to be one extra, to include an instance object to call the method on. This seems to work well when the instance method does not expect any parameters, but when the method excepts parameters I get the following error: Cannot convert supplied XPath value to the required type for the extension function. Does anyone have it working? Can anyone shoe me an example. here is my code: public class Taxonomy extend TaxonomyBase { private transient Map<String, String> itsTaxonomyMap; private transient Map<String, String> itsTaxonomyBase; public String getURL(String inTaxonomyMapKey, String inBaseKey) { return (getPrefix() + itsTaxonomyBase.get(inBaseKey) + itsTaxonomyMap.get(inTaxonomyMapKey) + kSuffix); } } public class XSLTTransform { ...... TransformerFactory theTransformerFactory = TransformerFactory.newInstance(); theTransformer = theTransformerFactory.newTransformer(theXsltSource); theTransformer.setParameter(theParameter.getKey(), );


Replies (2)

RE: non-static java methods calls fail on par - Added by Anonymous about 16 years ago

Legacy ID: #4869959 Legacy Poster: Michael Kay (mhkay)

Here's an example that seems to have all the essential ingredients of yours. Stylesheet: <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"> <xsl:param name="map"/> <xsl:template match="/" xmlns:HashMap="java:java.util.HashMap"> <out><xsl:value-of select="HashMap:get($map, 'cheese')"/></out> </xsl:template> </xsl:stylesheet> Java code: sourceID = "file:///c:/temp/test.xsl"; xslID = sourceID; // Create a transform factory instance. TransformerFactory tfactory = TransformerFactory.newInstance(); // Create a transformer for the stylesheet. Transformer transformer = tfactory.newTransformer(new StreamSource(xslID)); HashMap map = new HashMap(); map.put("cheese", "brie"); map.put("sausage", "cumberland"); transformer.setParameter("map", map); // Transform the source XML to System.out. transformer.transform(new StreamSource(sourceID), new StreamResult(System.out)); Output: <?xml version="1.0" encoding="UTF-8"?> <out xmlns:HashMap="java:java.util.HashMap">brie</out> Hope that helps.

RE: non-static java methods calls fail on params - Added by tomi crow almost 7 years ago

Hope this will help you to understand...static and non static methods in java

http://net-informations.com/java/cjava/nonstatic.htm

Crow

    (1-2/2)

    Please register to reply