Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > XSLT
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old September 4th, 2007, 08:27 AM
Registered User
 
Join Date: Sep 2007
Location: Manchester, , United Kingdom.
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
Reply With Quote
  #2 (permalink)  
Old September 4th, 2007, 08:55 AM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
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)
Reply With Quote
  #3 (permalink)  
Old September 4th, 2007, 09:11 AM
samjudson's Avatar
Friend of Wrox
Points: 8,687, Level: 40
Points: 8,687, Level: 40 Points: 8,687, Level: 40 Points: 8,687, Level: 40
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2007
Location: Newcastle, , United Kingdom.
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 -/
Reply With Quote
  #4 (permalink)  
Old October 9th, 2007, 03:58 PM
Registered User
 
Join Date: Oct 2007
Location: , , .
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!


Reply With Quote
  #5 (permalink)  
Old October 9th, 2007, 04:08 PM
mhkay's Avatar
Wrox Author
Points: 18,487, Level: 59
Points: 18,487, Level: 59 Points: 18,487, Level: 59 Points: 18,487, Level: 59
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
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
Reply With Quote
  #6 (permalink)  
Old October 20th, 2007, 07:48 PM
Registered User
 
Join Date: Oct 2007
Location: , , .
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.



Reply With Quote
  #7 (permalink)  
Old October 21st, 2007, 04:49 AM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
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)
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 06:24 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.