1

我将 Apache FOP 与我的 c# 代码中的 IKVM 一起使用。我通过使用 xslt 样式表生成 pdf 以获取 xsl fo 的结果。我有一个问题,那就是使用自定义函数。我的样式表声明:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:fo="http://www.w3.org/1999/XSL/Format"
                 xmlns:cal="xalan://m.test"
              extension-element-prefixes="cal"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://www.w3.org/2001/XMLSchema-instance http://www.xmlblueprint.com/documents/fop.xsd">

自定义函数:

namespace m
{
    public class test
    {
        public static string zzz(ExpressionContext x, object d)
        {
            return "test";
        }
    }
}

并从 xslt 调用它:

 <xsl:value-of select="cal:zzz(1)"/>

编译它的代码:

 FopFactory fopFactory = FopFactory.newInstance();
            fopFactory.ignoreNamespace("http://www.w3.org/2001/XMLSchema-instance");
            fopFactory.setUserConfig(new File("fop.xconf"));

            OutputStream o = new DotNetOutputMemoryStream();

            try
            {
                Fop fop = fopFactory.newFop("application/pdf", o);

                TransformerFactory factory = TransformerFactory.newInstance();

                Source xsltSrc = new StreamSource(new File("data.xsl"));
                Transformer transformer = factory.newTransformer(xsltSrc);

                var bytes = System.IO.File.ReadAllBytes("data.xml"); //"HR_CV.fo");
                var stream = new DotNetInputMemoryStream(new System.IO.MemoryStream(bytes));

                Source src = new StreamSource(stream);

                Result res = new SAXResult(fop.getDefaultHandler());

                transformer.transform(src, res);
            }
            finally
            {
                o.close();
            }

我得到的例外是:java.lang.NoSychMethodExtension:对于扩展函数,找不到方法 org.apache.xml.utils.NodeVector.zzz([ExpressionContext,])

我做错了什么?

4

1 回答 1

-1

You're calling the zzz function with a single argument (1). But your function expects two arguments. If you provide both arguments, chances are it will work just fine.

于 2012-10-12T09:18:04.923 回答