p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


Go Back   p2p.wrox.com Forums > XML > XSLT
I forgot my password Register Now
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 p2p Programmer to Programmer discussion community. This is a community of more than 40,000 computer programmers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining our free Wrox p2p community you can post your own programming questions and respond to other programmers’ questions. Registered users also don't have to see the ads that are displayed to guests. Registration is fast, simple and absolutely free so please, join today!
Join today and post to win prizes! Post more to increase your chances of being Wrox’s top poster of the month.

Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old July 11th, 2008, 05:53 AM
Authorized User
 
Join Date: Jul 2008
Location: , , .
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to vsempoux
Default insert current date

Hello all,

in my xslt i would like to insert a datestamp tag
eg: <CreationDate>25/10/2008</CreationDate>
The way i want it, is that the date is put in it automatically when the xml is transformed.
Is this possible ?

Greetings to all

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #2 (permalink)  
Old July 11th, 2008, 06:01 AM
mhkay's Avatar
Wrox Author
Points: 12,738, Level: 48
Points: 12,738, Level: 48 Points: 12,738, Level: 48 Points: 12,738, Level: 48
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 3,924
Thanks: 0
Thanked 82 Times in 80 Posts
Default

In XSLT 2.0 use the current-date() function (and format-date(), if you want it in dd/mm/yyyy format).

In XSLT 1.0 you'll have to pass the current date in as a stylesheet parameter from the calling application, or get it using an extension function call.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #3 (permalink)  
Old July 11th, 2008, 06:10 AM
Authorized User
 
Join Date: Jul 2008
Location: , , .
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to vsempoux
Default

Thanks,
But how do i call this function within my xslt?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #4 (permalink)  
Old July 11th, 2008, 06:35 AM
mhkay's Avatar
Wrox Author
Points: 12,738, Level: 48
Points: 12,738, Level: 48 Points: 12,738, Level: 48 Points: 12,738, Level: 48
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 3,924
Thanks: 0
Thanked 82 Times in 80 Posts
Default

These functions are just like count(), sum(), or substring() - you can use them within any XPath expression, for example the expression in

<xsl:value-of select="EXPR"/>

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #5 (permalink)  
Old July 11th, 2008, 06:38 AM
Authorized User
 
Join Date: Jul 2008
Location: , , .
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to vsempoux
Default

Ok,
when i try this <xsl:value-of select="current-date()"/> XMLspy tells me "XSL transformation failed due to following error:

'current-date' is not a valid XSLT or XPath function.

-->current-date()<-- "
How can i solve this ?

Thanks,

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #6 (permalink)  
Old July 11th, 2008, 06:53 AM
mhkay's Avatar
Wrox Author
Points: 12,738, Level: 48
Points: 12,738, Level: 48 Points: 12,738, Level: 48 Points: 12,738, Level: 48
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 3,924
Thanks: 0
Thanked 82 Times in 80 Posts
Default

As I said, it's an XSLT 2.0 function. Use a version of XML Spy that supports XSLT 2.0, and make sure that XSLT 2.0 is enabled.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #7 (permalink)  
Old July 11th, 2008, 07:27 AM
Authorized User
 
Join Date: Jul 2008
Location: , , .
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to vsempoux
Default

Ok, so far so good.
xslt 2.0 enabled and working

for the moment i have <xsl:value-of select="current-date()"/>
which returns me 2008-07-11+02:00.
how do i use the function format-date to get 11-07-2008.
i already tried to do like this
<xsl:value-of-select="format-date(current-date(),'DD-MM-YYYY')/>
but that gives me an error.

Any pointers ?

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #8 (permalink)  
Old July 11th, 2008, 07:42 AM
samjudson's Avatar
Friend of Wrox
Points: 4,453, Level: 28
Points: 4,453, Level: 28 Points: 4,453, Level: 28 Points: 4,453, Level: 28
Activity: 61%
Activity: 61% Activity: 61% Activity: 61%
 
Join Date: Aug 2007
Location: Newcastle, , United Kingdom.
Posts: 1,359
Thanks: 0
Thanked 31 Times in 31 Posts
Default

http://www.w3.org/TR/xslt20/#function-format-date

I think it should be something like this:

<xsl:value-of-select="format-date(current-date(),'[D]-[M]-[Y]')/>

/- Sam Judson : Wrox Technical Editor -/
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #9 (permalink)  
Old July 11th, 2008, 07:51 AM
Authorized User
 
Join Date: Jul 2008
Location: , , .
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to vsempoux
Default

YES YES,

That did it.

I was already looking at another possibility, namely define the current date as a variable and then use the concat and substring functions.
But when i did that i got the error that the variable i made was of type date and not of type string.
i declared my var like this
<xsl:variable name="CD" select="current-date()"/>
is there a simple way to say to xml that i want to use my variable as a string
(i already tried to this <xsl:variable name="CD" select="current-date()" as="string"/>
but that didn't work either :) )
Never the less, many thanks for your help...
V.

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #10 (permalink)  
Old July 11th, 2008, 07:57 AM
samjudson's Avatar
Friend of Wrox
Points: 4,453, Level: 28
Points: 4,453, Level: 28 Points: 4,453, Level: 28 Points: 4,453, Level: 28
Activity: 61%
Activity: 61% Activity: 61% Activity: 61%
 
Join Date: Aug 2007
Location: Newcastle, , United Kingdom.
Posts: 1,359
Thanks: 0
Thanked 31 Times in 31 Posts
Default

'string' isn't a data type, however 'xs:string' probably is (provided 'xs' has been defined as the prefix to the XML Schema namespace.

Alternatively you can just use the string() function to try to convert anything to a string. e.g. select="string(current-date())"

/- Sam Judson : Wrox Technical Editor -/
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
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

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Current Date s15199d Reporting Services 2 April 3rd, 2006 01:38 AM
trigger to insert current date on insert kev_79 SQL Server 2000 3 January 23rd, 2006 05:58 PM
Current Date rgudino Java Databases 1 May 5th, 2005 04:09 AM
How to make insert statments for current db method Access VBA 8 March 23rd, 2005 10:47 PM
Current Date?? morpheus SQL Server 2000 2 November 27th, 2003 04:21 PM



All times are GMT -4. The time now is 06:36 AM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
© 2008 Wiley Publishing, Inc