Re: [xslt] confusing error message "function format-date bound to undefined prefix date"

Viktor Stujber schrieb:
Greetings. We had some trouble when modifying our presentation layer
to use (e)xslt date formatting. The problematic code looked like this:

<xsl:value-of select="date:format-date(str:replace($date, ' ', 'T'),
'HH:mm:ss | dd. MMMM, yy')"/>

This line worked on its author's test setup, which used an older
libxslt version. But when deployed on our webserver, it started
throwing errors:

xmlXPathCompOpEval: function format-date bound to undefined prefix date
xmlXPathCompiledEval: 1 objects left on the stack.

First, the error message strongly suggests you haven't bound the prefix
"date" to a namespace. As a consequence, the XPath expression cannot be

Second, as this extension function isn't supported natively be LibXSLT,
which can be checked by doing `xsltproc --dumpextensions`, you have to
include the EXSLT function supplied by Jeni Tennison in your transform.

This has a dependency on "str.padding.function.xsl", which you can
remove when using LibXSLT, as it is implemented natively in this
processor. See the example below.

Michael Ludwig

<xsl:stylesheet version="1.0"

  <xsl:include href="date.format-date.function.xsl"/>

  <xsl:output method="text"/>

  <xsl:template match="/">
    <xsl:variable name="date" select="'2009-03-23 10:21:00'"/>
    <xsl:variable name="fmt"  select="'HH:mm:ss | dd. MMMM, yy'"/>

    <xsl:value-of select="str:replace( $date, ' ', 'T')"/>

    <xsl:value-of select="
      date:format-date( str:replace( $date, ' ', 'T'), $fmt)"/>


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]