简体   繁体   中英

XSLT xmlXPathCompOpEval: function new not found

I am trying to execute my xsl file and getting an error which says function new not found.

Command to execute my xsl: xsltproc GetRequestTransformation.xsl xsltTest.xml

Whenever I try to execute the above command in my Linux machine, I get the below error :

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 :

    <?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 :

<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. 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). If you want to execute this stylesheet from the command line you will need to download Xalan and run its command line tool

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:

<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).

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. libxslt also supports date:date-time() and date:difference() .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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