-
Enhancement
-
Resolution: Unresolved
-
P4
-
None
-
6
-
x86
-
windows_xp
A DESCRIPTION OF THE REQUEST :
with com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl,We're getting the following stacktrace when compiling a stylesheet with instance method calling on an a xsl parameter. The same code can pass with org.apache.xalan.processor.TransformerFactoryImpl:
ERROR: 'Cannot find external method 'Test.Bam.getMessage.' (must be public).'
FATAL ERROR: javax.xml.transform.TransformerConfigurationException: Could not compile stylesheet
at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl.n
wTemplates(Unknown Source)
at Test.UseStylesheetParam.main(UseStylesheetParam.java:64)
xception in thread "main" java.lang.NullPointerException
at Test.UseStylesheetParam.main(UseStylesheetParam.java:78)
JUSTIFICATION :
The same feature has already been in Apache Xalan.
---------- BEGIN SOURCE ----------
foo.xsl
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"
xmlns:Iteration="http://www.iterationsoftware.com"
xmlns:msxsl="urn:schemas-microsoft-com:xslt"
xmlns:HTML="http://www.w3.org/Profiles/XHTML-transitional"
xmlns:xalan="http://xml.apache.org/xalan"
xmlns:BAM="xalan://Test.Bam">
<xsl:output method="xml" encoding="UTF-8" omit-xml-declaration="yes" indent="no"/>
<xsl:param name="param1"/>
<xsl:variable name="BAMObject" select="$param1"/>
<xsl:template match="doc">
<out><xsl:value-of select="BAM:getMessage($BAMObject)"/></out>
</xsl:template>
</xsl:stylesheet>
foo.xml
<?xml version="1.0"?>
<doc>Hello</doc>
A simple java class.
package Test;
import java.util.Date;
public class Bam
{
String m_strMessage;
public Bam()
{
m_strMessage = "hello world";
}
public Bam(String strMessage)
{
m_strMessage = strMessage;
}
public String getMessage()
{
String strVal = "Hello " + m_strMessage + "! Current time is: " + new Date().toString();
return strVal;
}
}
Sample code to transform the foo.xml
// Get the parameter value from the command line.
Bam oBam = new Bam(args[0]);
//String paramValue = oBam.toString();
Bam paramValue = oBam;
TransformerFactory tFactory = TransformerFactory.newInstance();
Templates templates = tFactory.newTemplates(new StreamSource("foo.xsl"));
Transformer transformer = templates.newTransformer();
transformer.setParameter("param1", /* parameter name */
paramValue /* parameter value */ );
transformer.transform(new StreamSource("foo.xml"), new StreamResult(new OutputStreamWriter(System.out)));
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Create the instance in XSLT instead of Java code.
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"
xmlns:Iteration="http://www.iterationsoftware.com"
xmlns:msxsl="urn:schemas-microsoft-com:xslt"
xmlns:HTML="http://www.w3.org/Profiles/XHTML-transitional"
xmlns:xalan="http://xml.apache.org/xalan"
xmlns:BAM="xalan://Test.Bam">
<xsl:output method="xml" encoding="UTF-8" omit-xml-declaration="yes" indent="no"/>
<xsl:param name="param1"/>
<xsl:variable name="BAMObject" select="$param1"/>
<xsl:variable name="BAMObject2" select="BAM:new()"/>
<xsl:template match="doc">
<out><xsl:value-of select="BAM:getMessage($BAMObject2)"/></out>
</xsl:template>
</xsl:stylesheet>
with com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl,We're getting the following stacktrace when compiling a stylesheet with instance method calling on an a xsl parameter. The same code can pass with org.apache.xalan.processor.TransformerFactoryImpl:
ERROR: 'Cannot find external method 'Test.Bam.getMessage.' (must be public).'
FATAL ERROR: javax.xml.transform.TransformerConfigurationException: Could not compile stylesheet
at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl.n
wTemplates(Unknown Source)
at Test.UseStylesheetParam.main(UseStylesheetParam.java:64)
xception in thread "main" java.lang.NullPointerException
at Test.UseStylesheetParam.main(UseStylesheetParam.java:78)
JUSTIFICATION :
The same feature has already been in Apache Xalan.
---------- BEGIN SOURCE ----------
foo.xsl
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"
xmlns:Iteration="http://www.iterationsoftware.com"
xmlns:msxsl="urn:schemas-microsoft-com:xslt"
xmlns:HTML="http://www.w3.org/Profiles/XHTML-transitional"
xmlns:xalan="http://xml.apache.org/xalan"
xmlns:BAM="xalan://Test.Bam">
<xsl:output method="xml" encoding="UTF-8" omit-xml-declaration="yes" indent="no"/>
<xsl:param name="param1"/>
<xsl:variable name="BAMObject" select="$param1"/>
<xsl:template match="doc">
<out><xsl:value-of select="BAM:getMessage($BAMObject)"/></out>
</xsl:template>
</xsl:stylesheet>
foo.xml
<?xml version="1.0"?>
<doc>Hello</doc>
A simple java class.
package Test;
import java.util.Date;
public class Bam
{
String m_strMessage;
public Bam()
{
m_strMessage = "hello world";
}
public Bam(String strMessage)
{
m_strMessage = strMessage;
}
public String getMessage()
{
String strVal = "Hello " + m_strMessage + "! Current time is: " + new Date().toString();
return strVal;
}
}
Sample code to transform the foo.xml
// Get the parameter value from the command line.
Bam oBam = new Bam(args[0]);
//String paramValue = oBam.toString();
Bam paramValue = oBam;
TransformerFactory tFactory = TransformerFactory.newInstance();
Templates templates = tFactory.newTemplates(new StreamSource("foo.xsl"));
Transformer transformer = templates.newTransformer();
transformer.setParameter("param1", /* parameter name */
paramValue /* parameter value */ );
transformer.transform(new StreamSource("foo.xml"), new StreamResult(new OutputStreamWriter(System.out)));
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Create the instance in XSLT instead of Java code.
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"
xmlns:Iteration="http://www.iterationsoftware.com"
xmlns:msxsl="urn:schemas-microsoft-com:xslt"
xmlns:HTML="http://www.w3.org/Profiles/XHTML-transitional"
xmlns:xalan="http://xml.apache.org/xalan"
xmlns:BAM="xalan://Test.Bam">
<xsl:output method="xml" encoding="UTF-8" omit-xml-declaration="yes" indent="no"/>
<xsl:param name="param1"/>
<xsl:variable name="BAMObject" select="$param1"/>
<xsl:variable name="BAMObject2" select="BAM:new()"/>
<xsl:template match="doc">
<out><xsl:value-of select="BAM:getMessage($BAMObject2)"/></out>
</xsl:template>
</xsl:stylesheet>