如何从 xslt 调用 java 对象函数

How to call a java object function from xslt

我正在使用 xalan 进行 xml/xslt 转换。我可以使用

将 Java 对象传递给 xslt

transformer.setParameter("parameterName",parameterValue);

我也可以从 xslt 获取此值,但我想从 parameterValue 具有的 xslt 调用我的函数。假设我初始化了 parameterValue

ParameterValue parameterValue = new ParameterValue("value");

ParameterValue 有一个名为 getValue 的函数。如何从 xslt.

调用此函数

我试过了;

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

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

但 none 有效。我该怎么做?

https://xalan.apache.org/xalan-j/extensions_xsltc.html#java_ext 处的文档建议使用:

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

确保,如果 ParameterValue 存在于一个包中(例如 example.com.ParameterValue),您可以将其与

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