whyvez
whyvez

Reputation: 43

xpath function not recognized in xslt

I am debugging an xslt stylesheet in Oxygen using the xalan processor. I cannot seem to get the current-time() or hours-from-time() functions to work. I get a "could not find function" error. What am i doing wrong? here is the code.

<xsl:variable name="isPm" select="hours-from-time(n1:TIME_REPORT) &gt;= 12"/>

Upvotes: 2

Views: 3367

Answers (3)

lavinio
lavinio

Reputation: 24319

hours-from-time and current-time are XPath 2.0 functions. Xalan only supports XPath 1.0.

Later versions of Xalan support extension functions which will give some of this functionality. Both of the function you are looking for are there, in some form. Note that since XPath 1.0 doesn't understand date times you'll be dealing with strings. But see, for example:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:date="http://exslt.org/dates-and-times" extension-element-prefixes="date">
    <xsl:template match="/">
        <html>
            <head>
                <title>Current Date Test</title>
            </head>
            <body>
                <h1>It's now <xsl:value-of select="date:date-time()"/>.</h1>
            </body>
        </html>
    </xsl:template>
</xsl:stylesheet>

See both the Xalan Extension Function page and also the EXSLT Extension Function page for Dates and Times.

Upvotes: 4

Dimitre Novatchev
Dimitre Novatchev

Reputation: 243569

I am debugging an xslt stylesheet in Oxygen using the xalan processor. 

I cannot seem to get the current-time() or hours-from-time() functions to work. I get a "could not find function" error.

As noted by @lavinio and @Alejandro, these two functions were introduced in XPath 2.0, which is not supported by Xalan.

You may pass the current time as a parameter to the XSLT 1.0 transformation.

Do note, that even in XPath 2.0, multiple evaluations of the current-time() during a transformation, return the same value. So this function doesn't give you anything more than what you get by passing the current time as a parameter.

Upvotes: 2

user357812
user357812

Reputation:

Those aren't standard XPath 1.0 functions. If your processor has those functions implemented as extensions, then you should add the correct namespace for them.

From http://www.w3.org/TR/xslt#section-Extension-Functions

If a FunctionName in a FunctionCall expression is not an NCName (i.e. if it contains a colon), then it is treated as a call to an extension function. The FunctionName is expanded to a name using the namespace declarations from the evaluation context.

If the XSLT processor does not have an implementation of an extension function of a particular name available, then the function-available function must return false for that name. If such an extension function occurs in an expression and the extension function is actually called, the XSLT processor must signal an error. An XSLT processor must not signal an error merely because an expression contains an extension function for which no implementation is available.

If the XSLT processor has an implementation of an extension function of a particular name available, then the function-available function must return true for that name. If such an extension is called, then the XSLT processor must call the implementation passing it the function call arguments; the result returned by the implementation is returned as the result of the function call.

Upvotes: 1

Related Questions