我正在尝试使用 java 中的 Saxon 处理器。我正在使用saxon9ee.jar里面 saxonee9-3-0-11j.zip (刚刚下载,没有许可证 - 是否需要它才能工作?)
Their **可以在这里找到资源:http://www.saxonica.com/documentation/extensibility/functions/instance-methods.xml
http://www.saxonica.com/documentation/extensibility/functions/staticmethods.xml
My 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 函数?