我正在尝试使用来自 java 的 Saxon 处理器。我正在使用 saxone9-3-0-11j.zip 中的 saxon9ee.jar(刚刚下载,没有许可证 - 需要它才能工作吗?)
他们的** 资源可以在这里找到: http://www.saxonica.com/documentation/extensibility/functions/instance-methods.xml
http://www.saxonica.com/documentation/extensibility/functions/staticmethods.xml
我的 xsl:
<?xml version="1.0"?>
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:template match="/">
<xsl:value-of select="dateUtils:getCurrentFullDate()"
xmlns:dateUtils="java:com.macfaq.math.SimpleSaxon"/>
</xsl:template>
</xsl:stylesheet>
我的java文件:
package com.macfaq.math;
public class SimpleSaxon {
public static final String YMDTHMS = "yyyyMMdd'T'hhmmss";
public static String getCurrentFullDate() {
return (new SimpleDateFormat(YMDTHMS).format(new Date()));
}
}
我的输入 XML 文件:
<?xml version="1.0" encoding="UTF-8"?>
<date format="yyyyMMdd'T'hhmmss" year="2000" month="4" day="27"/>
我的主要java文件:
public class SaxonTransf {
public static void main(String[] args) {
System.setProperty("javax.xml.transform.TransformerFactory",
"net.sf.saxon.TransformerFactoryImpl");
String foo_xml = "in.xml"; // input xml
String foo_xsl = "transf.xsl"; // input xsl
TransformerFactory tfactory = TransformerFactory.newInstance();
Transformer transformer = tfactory.newTransformer(new StreamSource(
new File(foo_xsl)));
transformer.transform(new StreamSource(new File(foo_xml)),
new StreamResult(System.out));
}
错误: XTDE1425:找不到匹配的名为 0 参数的函数 {java:com.macfaq.math.SimpleSaxon}getCurrentFullDate()。命名空间 URI 和本地名称 被识别,但内置模板规则中的参数数量错误。
有没有人在使用这个出色的处理器时幸运地从 XSL 调用自定义 Java 函数?
最佳答案
当您使用 Saxon-EE JAR 文件但没有许可证运行 Saxon 时,那么(至少在理论上)它的行为应该与 Saxon-HE 完全一样,这意味着不支持这种扩展函数调用方式。
如果您从命令行运行,-TJ 选项将为您提供更详细的诊断,详细说明匹配函数的搜索。
关于java - 从 XSL (SAXON) 调用 Java,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9925483/