views:

149

answers:

1

I added the EXSLT dates-and-times module in my XSLT 1.0 file by declaring:

    <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">

This doesn't affect my resulting page, but when I try to call the actual date with:

<xsl:value-of select="date:date-time()"/>

I receive an "Error loading stylesheet: An unknown error has occurred ()" message when loading my page. Does anyone have a suggestion as to what I might be missing? Thanks in advance!

+1  A: 

but when I try to call the actual date with:

<xsl:value-of select="date:date-time()"/>

I receive an "Error loading stylesheet: An unknown error has occurred ()" message when loading my page

This means that the particular XSLT processor you're using doesn't implement EXSLT (or just the date-time module of EXSLT).

Here is a small transformation:

<xsl:stylesheet version="1.0"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
 xmlns:date="http://exslt.org/dates-and-times"
 >
 <xsl:output method="text"/>

 <xsl:template match="/">
   <xsl:value-of select="date:date-time()"/>
 </xsl:template>
</xsl:stylesheet>

when applied to any XML document (not used), with the Saxon 6.5.4 XSLT 1.0 processor, the correct result is produced:

2010-05-22T12:49:44-07:00

Solution:

Either use an XSLT 1.0 processor that implements EXSLT, or pass the current date-time as a parameter to the transformation.

If using XSLT 2.x, just use the XPath 2.0 function current-dateTime().

Dimitre Novatchev
I would probably have to pass the current date-time as a parameter--what would you recommend to get the current date-time initially?
danielle
@danielle: There should be such a method/function in the programming language from which you are starting the transformation. For example, in C# this is `DateTime.Now.ToString()`
Dimitre Novatchev