[英]XSLT xmlXPathCompOpEval: function new not found
我正在嘗試執行我的xsl文件,並收到一條錯誤消息,提示未找到新功能。
執行我的xsl的命令: xsltproc GetRequestTransformation.xsl xsltTest.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>
映射XML文件xsltTest.xml :
<tTroubleticket>
<alarms>
<tTroubleticketalarm>
<activationDate>2015-04-01 12:42:22.0</activationDate>
<clearDate>null</clearDate>
</tTroubleticketalarm>
</alarms>
</tTroubleticket>
您能否嘗試找出我的xsl文件的問題。 我在執行該命令之前會丟失任何東西嗎? 我該如何解決?
您嘗試使用的Java擴展功能機制特定於Xalan Java XSLT處理器,在xsltproc
(不是用Java編寫)中不起作用。 如果要從命令行執行此樣式表,則需要下載Xalan並運行其命令行工具
java -cp xalan.jar:serializer.jar org.apache.xalan.xslt.Process -XSL GetRequestTransformation.xsl -IN xsltTest.xml
第14行,在Date:new()
:括住括號和引號:
<xsl:variable name="currentDate" select="SimpleDateFormat:format(SimpleDateFormat:new('yyyy-MM-dd HH:mm:ss'), Date:new())" />
伊恩·羅伯茨的眼神比我大。 假定命令行是由用Java編寫的處理器(即Xalan或Saxon)運行的,我僅瀏覽了命令行部分並僅關注您的XSLT代碼。
FWIW,您不需要使用Java來獲取當前日期:libxslt和Xalan都支持EXSLT date:date()
和date:time()
擴展功能。 libxslt還支持date:date-time()
和date:difference()
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.