【发布时间】:2012-03-29 12:37:18
【问题描述】:
我正在尝试使用 java 中的 Saxon 处理器。我正在使用 saxonee9-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 函数?
【问题讨论】:
标签: java xslt stylesheet transformation saxon