Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 4th, 2007, 08:27 AM
Registered User
 
Join Date: Sep 2007
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Current Date and Time in XSLT

Hi Everybody,

First of all let me say hi, i'm new to the boards so go easy on me.

I've searched through the forum looking for an answer to a niggling problem I have with an XSL stylesheet. I receive a <startDate> through my XML and I would like to display this date as a count down. For example 99days 8hours 9minutes - until next event.

I do not need my countdown to be a 'live' countdown (like you would see in DHTML or similar.) As the page loads I simply want to attach the current date and time to a variable so I can calculate accordingly.

Searching the internet has uncovered a few options (http://exslt.org/date/index.html) but after experimenting with them I have been unable to fix this problem. Has anyone got a quick fix??

Thanks in advance

devMc
 
Old September 4th, 2007, 08:55 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

If you need access to the current date during your transform then there are a number of options:
  • Pass in the current date as a parameter
  • Use an extension function, how you do this is processor specific, in .NET you can use C# for example
  • Use the current-date() function (XSLT 2.0 only)

If that's not what you need can you be a bit more specific?

--

Joe (Microsoft MVP - XML)
 
Old September 4th, 2007, 09:11 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

What have you tried exactly?

Are you using XSLT 2.0 and XPath 2.0, in which case you should be able to use the days-from-duration(), hours-from-duration() and minutes-from-duration() functions.

/- Sam Judson : Wrox Technical Editor -/
 
Old October 9th, 2007, 03:58 PM
Registered User
 
Join Date: Oct 2007
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Well now, days-from-duration(). Exactly what I'm looking for. Tried a few things ...
Sharepoint list with a single item of historical date, say 2006-01-02 (yyyy-mm-dd) for example. Can display the item itself fine. Want to do a calculation using days-from-duration() within the XSLT that runs through a webpart.

Want to display Integer value on a Dashboard. Without the calculation, this line makes the output:
<xsl:value-of select="LIRDate"/>

I've added this to the stylesheet as a variable:
<xsl:variable name="TheDate" select="LIRDate"/>

Wanted to do this:
<xsl:value-of select="days-from-duration($TheDate)"/>

but I get a:

Failed setting processor stylesheet : 0x80004005 : 'days-from-duration' is not a valid XSLT or XPath function. -->days-from-duration($TheDate)<--

Wow, I'd better run out and buy another Wrox Book!


 
Old October 9th, 2007, 04:08 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

days-from-duration() is an XPath 2.0 function, looks as if you called it from a 1.0 processor.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old October 20th, 2007, 07:48 PM
Registered User
 
Join Date: Oct 2007
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I have searched the internet for a very long time and I know you cannot get the current date in XSLT 1.0 but you can in XSLT 2.0. I found forums posting the function below:

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

But I get errors. Can someone tell me how to use the functions in XSLT 2.0? Am I missing something some declarations at the top of the XSL stylesheet? If you can post some sample code it will be very helpful since I cannot find any. What I want to do is get the current date and save it into a variable so that I can use it later in the transformation by comparing with dates in the XML. Someone suggested using javascript to retrieve the current date but how do I it.

Many thanks in advance.



 
Old October 21st, 2007, 04:49 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

If you looked in this forum, a few posts back in this thread, you'd have seen the correct format, current-date(). In general XSLT uses the dash (-) rather than the underscore (_) to separate words in function names.

--

Joe (Microsoft MVP - XML)





Similar Threads
Thread Thread Starter Forum Replies Last Post
getting current date and time in xslt 1.0 ashyabhi_hp XSLT 1 September 24th, 2007 03:17 AM
Current date time in XSLT verison 1.0 ksskumar XSLT 1 October 17th, 2006 07:58 AM
how to get current date & time from client machine swati_joshi ASP.NET 1.0 and 1.1 Basics 2 April 28th, 2006 10:18 AM
current date in XSLT 1.0 pendyalap XSLT 1 April 18th, 2006 06:13 PM
Getting the Current Date in XSLT kwilliams XSLT 2 November 30th, 2005 03:23 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.