xalan和xslt的自定义函数

时间:2012-10-10 11:33:44

标签: xslt xalan ikvm

我正在使用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,])

我做错了什么?

1 个答案:

答案 0 :(得分:-1)

您使用单个参数(1)调用zzz函数。但是你的函数需要两个参数。如果你提供两个参数,很可能它会正常工作。