Java XSLT xmlXPathCompOpEval:未找到新函数
我试图执行我的xsl文件,但得到一个错误,该错误表示找不到新函数 执行我的xsl的命令:Java XSLT xmlXPathCompOpEval:未找到新函数,java,xml,date,xslt,Java,Xml,Date,Xslt,我试图执行我的xsl文件,但得到一个错误,该错误表示找不到新函数 执行我的xsl的命令:xsltproc GetRequestTransformation.xsl xsltest.xml 每当我尝试在我的Linux机器上执行上述命令时,都会出现以下错误: compilation error: file GetRequestTransformation.xsl line 5 element stylesheet xsl:version: only 1.0 features are supporte
xsltproc GetRequestTransformation.xsl xsltest.xml
每当我尝试在我的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'.
这是我的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>
第14行,在Date:new()之后:关闭括号和引号:
<xsl:variable name="currentDate" select="SimpleDateFormat:format(SimpleDateFormat:new('yyyy-MM-dd HH:mm:ss'), Date:new())" />
编辑:
伊恩·罗伯茨的眼睛比我的更锐利;我浏览了命令行部分,只关注XSLT代码,假设它由Java编写的处理器(即Xalan或Saxon)运行
FWIW,您不需要使用Java来获取当前日期:libxslt和Xalan都支持EXSLTdate:date()
和date:time()
扩展函数。libxslt还支持date:date-time()
和date:difference()。如果希望从命令行执行此样式表,则需要下载Xalan并运行其
您能告诉我配置EXSLT需要做什么吗?只需声明相关名称空间并使用函数-请参阅:我需要在类路径中添加任何JAR吗?我相信我应该下载您共享的上述链接中提供的zip文件。但不幸的是,这些文件在GItHubNo上不可用,我刚才说的就是它。-jar和classpath是Java语言。这令人困惑。你真的在用Java做这个吗?正如Ian提到的,xsltproc不是Java;它调用用C编写的libxslt处理器。
<xsl:variable name="currentDate" select="SimpleDateFormat:format(SimpleDateFormat:new('yyyy-MM-dd HH:mm:ss'), Date:new())" />
java -cp xalan.jar:serializer.jar org.apache.xalan.xslt.Process -XSL GetRequestTransformation.xsl -IN xsltTest.xml