简体   繁体   English

XSLT xmlXPathCompOpEval:找不到新功能

[英]XSLT xmlXPathCompOpEval: function new not found

I am trying to execute my xsl file and getting an error which says function new not found. 我正在尝试执行我的xsl文件,并收到一条错误消息,提示未找到新功能。

Command to execute my xsl: xsltproc GetRequestTransformation.xsl xsltTest.xml 执行我的xsl的命令: xsltproc GetRequestTransformation.xsl xsltTest.xml

Whenever I try to execute the above command in my Linux machine, I get the below error : 每当我尝试在Linux机器上执行上述命令时,都会出现以下错误:

compilation error: file GetRequestTransformation.xsl line 5 element stylesheet
xsl:version: only 1.0 features are supported
xmlXPathCompOpEval: function new not found
XPath error : Unregistered function
xmlXPathCompOpEval: parameter error
runtime error: file GetRequestTransformation.xsl line 15 element variable
Failed to evaluate the expression of variable 'currentDate'.

Here is my XSLT file GetRequestTransformation.xsl : 这是我的XSLT文件GetRequestTransformation.xsl

    <?xml version='1.0' encoding='UTF-8'?>
<xsl:stylesheet version='2.0'
        xmlns:xsl='http://www.w3.org/1999/XSL/Transform'
        xmlns:java="http://xml.apache.org/xslt/java" xmlns:SimpleDateFormat="java.text.SimpleDateFormat"
        xmlns:Date="java.util.Date" exclude-result-prefixes="java SimpleDateFormat Date">
        <xsl:template match="/">
                <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:max="http://www.ibm.com/maximo">
                    <soapenv:Header/>
                    <soapenv:Body>
                        <max:CreateWS_INCID_AFEC_TB>
                            <max:WS_INCID_AFEC_TBSet>
                                <max:DURACION>
                                    <xsl:variable name="affectedFinish" select='/tTroubleticket/alarms/tTroubleticketalarm/clearDate' />
                                    <xsl:variable name="affectedStart" select='/tTroubleticket/alarms/tTroubleticketalarm/activationDate' />
                                    <xsl:variable name="currentDate" select="SimpleDateFormat:format(SimpleDateFormat:new('yyyy-MM-dd HH:mm:ss'), Date:new() />
                                    <xsl:choose>
                                        <xsl:when test="$affectedFinish != null">
                                            <xsl:value-of select="$affectedFinish - $affectedStart" />
                                        </xsl:when>
                                        <xsl:otherwise>
                                            <xsl:value-of select="$currentDate - $affectedStart" />
                                        </xsl:otherwise>
                                    </xsl:choose>
                                </max:DURACION>
                            </max:WS_INCID_AFEC_TBSet>
                        </max:CreateWS_INCID_AFEC_TB>
                    </soapenv:Body>
                </soapenv:Envelope>
            </xsl:template>
</xsl:stylesheet>

Mapping XML file xsltTest.xml : 映射XML文件xsltTest.xml

<tTroubleticket>
<alarms>
        <tTroubleticketalarm>
                <activationDate>2015-04-01 12:42:22.0</activationDate>
                <clearDate>null</clearDate>
        </tTroubleticketalarm>
    </alarms>
</tTroubleticket>

Could you please try to find out the issue with my xsl file. 您能否尝试找出我的xsl文件的问题。 Am I missing anything before I execute that command? 我在执行该命令之前会丢失任何东西吗? How can I fix it? 我该如何解决?

The Java extension function mechanism you're trying to use is specific to the Xalan Java XSLT processor and will not work in xsltproc (which is not written in Java). 您尝试使用的Java扩展功能机制特定于Xalan Java XSLT处理器,在xsltproc (不是用Java编写)中不起作用。 If you want to execute this stylesheet from the command line you will need to download Xalan and run its command line tool 如果要从命令行执行此样式表,则需要下载Xalan并运行其命令行工具

java -cp xalan.jar:serializer.jar org.apache.xalan.xslt.Process -XSL GetRequestTransformation.xsl -IN xsltTest.xml

Line 14, after Date:new() : close the parentheses and the quotes: 第14行,在Date:new() :括住括号和引号:

<xsl:variable name="currentDate" select="SimpleDateFormat:format(SimpleDateFormat:new('yyyy-MM-dd HH:mm:ss'), Date:new())" />

Edit: 编辑:

Ian Roberts' eyes are sharper than mine; 伊恩·罗伯茨的眼神比我大。 I skimmed over the command line section and concentrated on your XSLT code only, assuming it's being run by a processor written in Java (ie either Xalan or Saxon). 假定命令行是由用Java编写的处理器(即Xalan或Saxon)运行的,我仅浏览了命令行部分并仅关注您的XSLT代码。

FWIW, you don't need to use Java to get the current date: the EXSLT date:date() and date:time() extension functions are supported by both libxslt and Xalan. FWIW,您不需要使用Java来获取当前日期:libxslt和Xalan都支持EXSLT date:date()date:time()扩展功能。 libxslt also supports date:date-time() and date:difference() . libxslt还支持date:date-time()date:difference()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM