java xsl 自定义函数,在XSLT和SAXON中运行自定义Java函数(9.1.8)

Meta

Saxon XSLT processor (v. 9.1.8)

Java

XSLT 2.0

I got a simple example of a java class file and some xsl transformation. My goal is to run my custom java functions from the class file within the XSLT process (via SAXON). How is this possible? When I start the below described batch file the cmd displays an error calling me the function is not known to saxon. So I have to add my class to the Java / or Saxon CLASSPATH?

The transformation should copy all XML data and (return &) display the dimension of imagefiles.

My XSL Transformation

xmlns:xsl="http://www.w3.org/1999/XSL/Transform"

xmlns:ImageInfo="java:ImageInfo"

version="2.0">

[image] file found: x

Java Class

import javax.swing.ImageIcon;

public class ImageInfo {

String filename;

ImageIcon img;

public ImageInfo(String filename) {

this.filename = filename;

img = new ImageIcon(filename);

}

public int getWidth() {

return img.getIconWidth();

}

public int getHeight() {

return img.getIconHeight();

}

}

Saxon command line call (via .BAT)

java -jar "%~dp0\saxonb9-1-0-8j\saxon9.jar" -s:"data.xml" -xsl:"transformation.xsl" -o:"result.xml"

解决方案

You need the -cp option of your java command e.g. java -cp ".;%~dp0\saxonb9-1-0-8j\saxon9.jar" net.sf.saxon.Transform -s:"data.xml" -xsl:"transformation.xsl" -o:"result.xml" where you need to make sure that the directory with your ImageInfo is on the class path, I have added ., assuming the class is in your current working directory.

However, note that ImageInfo:getImageWidth(@src) would try to call a static method getImageWidth, you have instance methods, the method you have is called getWidth and it does not take an argument.

See the documentation for that old version of Saxon 9, it should be available on http://saxon.sourceforge.net/.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值