XSL 转换无法调用用户定义的 Java 方法

发布于 2024-09-28 18:04:47 字数 855 浏览 0 评论 0原文

我有以下 XSL,它为我的 Java 类定义了命名空间。简而言之,我试图根据 XML 文件中的值指向不同的资源包(我知道资源包确实用于国际化,但为什么要重新创建轮子?):

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
                xmlns:fo="http://www.w3.org/1999/XSL/Format"
                xmlns:java="http://xml.apache.org/xalan/java"
                xmlns:pf="my.package.common.PropertiesFinder">

    <xsl:variable name="compType" select="//comp_type"/>
    <xsl:variable name="props" select="pf:getPropsFile($compType)"/>
    <xsl:variable name="DEF6Resources" select="java:util.ResourceBundle.getBundle($props)"/>

当转换运行时,我收到以下错误:

java.lang.NoSuchMethodException:对于扩展函数,找不到方法 org.apache.xml.utils.NodeVector.getProps([ExpressionContext,])

任何人都可以解释为什么会发生这种情况。这显然与我的类路径/加载器有关,但我不知道该怎么做......

提前非常感谢。

安娜

I have the following XSL which defines a namespace for my Java Class. In a nutshell I'm trying to point to a different resource bundle depending upon a value in my XML file (I know Resource Bundles are really for internationalization but why re-create the wheel?):

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
                xmlns:fo="http://www.w3.org/1999/XSL/Format"
                xmlns:java="http://xml.apache.org/xalan/java"
                xmlns:pf="my.package.common.PropertiesFinder">

    <xsl:variable name="compType" select="//comp_type"/>
    <xsl:variable name="props" select="pf:getPropsFile($compType)"/>
    <xsl:variable name="DEF6Resources" select="java:util.ResourceBundle.getBundle($props)"/>

When the transform runs I get the following error:

java.lang.NoSuchMethodException: For extension function, could not find method org.apache.xml.utils.NodeVector.getProps([ExpressionContext,])

Can anyone shed any light on why this is happening please. It's clearly something to do with my classpath/loader but I'm not sure what to do...

Many thanks in advance.

Anna

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

溺ぐ爱和你が 2024-10-05 18:04:47

您必须检查您的名称空间定义。

xmlns:pf="my.package.common.PropertiesFinder"

当您为 Java 类定义命名空间时,必须在其前面添加 java: 前缀。

xmlns:pf="java:my.package.common.PropertiesFinder"

此外,调用的方法 (getPropsFile) 必须声明为 static

而且,我认为在这段代码中:

<xsl:variable name="DEF6Resources" select="java:util.ResourceBundle.getBundle($props)"/>

您缺少 java 根包:(

<xsl:variable name="DEF6Resources" select="java:java.util.ResourceBundle.getBundle($props)"/>

我不确定最后一个,也许 Xalan 解析器在某些情况下会在前面添加它?)

You have to check your namespace definition.

xmlns:pf="my.package.common.PropertiesFinder"

When you are defining a namespace for a Java class, you have to prepend it with the java: prefix.

xmlns:pf="java:my.package.common.PropertiesFinder"

Also, the method invoked (getPropsFile) must be declared as static.

And, I think that at this block of code:

<xsl:variable name="DEF6Resources" select="java:util.ResourceBundle.getBundle($props)"/>

You are missing the java root package:

<xsl:variable name="DEF6Resources" select="java:java.util.ResourceBundle.getBundle($props)"/>

(I'm not sure of this last, maybe the Xalan parser prepends it for some cases?)

忆沫 2024-10-05 18:04:47

遇到同样的问题。

最后我发现 Xalan 无法加载带有静态块或静态变量或类似内容的类。
也许 PropertiesFinderResourceBundle 在内部使用静态块。
该错误消息确实具有误导性......

Got same problem.

Finally I found that Xalan is unable to load classes with static blocks or static variables, or something like that.
Maybe PropertiesFinder or ResourceBundle use static blocks internally.
The error message was really misleading...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文