title: How can I call a method on a Java instance passed into XSLT?
body: <p>I need to have XSLT call a method on a Java instance that I pass as a parameter.  So far I can only get it to work if I create the instance in the XSLT itself.  If I attempt to call it on the passed instance it fails with</p>
  
  <pre><code>Exception in thread "main" javax.xml.transform.TransformerConfigurationException: 
  Cannot find external method 'Test.get' (must be public).
  </code></pre>
  
  <p>I can prove the instance is being passed ok by outputting it (it comes out as the toString).  Here is my Java:</p>
  
  <pre><code>public class Test {
  
      public static void main(String[] args) throws Exception {
          Transformer transformer = TransformerFactory.newInstance()
              .newTransformer(
              new StreamSource(Test.class.getResourceAsStream("test.xsl")));
          transformer.setParameter("test1", new Test());
          ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
          transformer.transform(new StreamSource(
              new ByteArrayInputStream(
              "&lt;?xml version=\"1.0\"?&gt;&lt;data&gt;&lt;/data&gt;".getBytes())),
              new StreamResult(outputStream));
          System.out.println(outputStream.toString());
      }
  
      public String get() {
          return "hello";
      }
  
      @Override
      public String toString() {
          return "An instance of Test";
      }
  }
  </code></pre>
  
  <p>and here is my xsl:</p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;
  &lt;xsl:stylesheet version="1.0"
                  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                  xmlns:test="xalan://Test"
                  exclude-result-prefixes="test"
  &gt;
  
      &lt;xsl:param name="test1" /&gt;
      &lt;xsl:variable name="test2" select="$test1"/&gt;
      &lt;xsl:variable name="test3" select="test:new()"/&gt;
  
      &lt;xsl:template match="/"&gt;
          &lt;data&gt;
              &lt;!-- proves that the instance is really being passed --&gt;
              &lt;xsl:value-of select="$test1"/&gt;
          &lt;/data&gt;
          &lt;data&gt;
              &lt;!-- first two do not work --&gt;
              &lt;!--&lt;xsl:value-of select="test:get($test1)"/&gt;--&gt;
              &lt;!--&lt;xsl:value-of select="test:get($test2)"/&gt;--&gt;
              &lt;!-- this one does work --&gt;
              &lt;xsl:value-of select="test:get($test3)"/&gt;
          &lt;/data&gt;
      &lt;/xsl:template&gt;
  &lt;/xsl:stylesheet&gt;
  </code></pre>
  
  <p>Does anyone know how I can make this work with the passed parameter?  Instantiating it in the XSLT is not going to work in my actual use case.  Thanks.</p>