[SOLVED] How to call a java object function from xslt

Issue

I am using xalan to make xml/xslt transformation. I can pass a Java object to xslt using

transformer.setParameter("parameterName",parameterValue);

Also I can get this value from xslt but I want to call I function from xslt that parameterValue has. Let’s assume I innitialize parameterValue

ParameterValue parameterValue = new ParameterValue("value");

and ParameterValue has a function called getValue. How can I call this function from xslt.

I tried;

<xsl:value-of select="$parameterName:getValue()">

and

<xsl:value-of select="$parameterName.getValue()">

but none worked. How can I do this?

Solution

The documentation at https://xalan.apache.org/xalan-j/extensions_xsltc.html#java_ext suggests to use:

<xsl:stylesheet xmlns:pv="http://xml.apache.org/xalan/java/ParameterValue" ...>
  <xsl:value-of select="pv:getValue($parameterName)"/>

Make sure, if ParameterValue lives in a package (e.g. example.com.ParameterValue) that you use that with e.g.

<xsl:stylesheet xmlns:pv="http://xml.apache.org/xalan/java/example.com.ParameterValue" ...>
  <xsl:value-of select="pv:getValue($parameterName)"/>

Answered By – Martin Honnen

Answer Checked By – Robin (BugsFixing Admin)

Leave a Reply

Your email address will not be published.