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

July 11th, 2008, 05:53 AM
|
|
Authorized User
|
|
Join Date: Jul 2008
Location: , , .
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|

July 11th, 2008, 06:01 AM
|
 |
Wrox Author
Points: 12,738, Level: 48 |
|
|
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 3,924
Thanks: 0
Thanked 82 Times in 80 Posts
|
|
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
|

July 11th, 2008, 06:10 AM
|
|
Authorized User
|
|
Join Date: Jul 2008
Location: , , .
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thanks,
But how do i call this function within my xslt?
|

July 11th, 2008, 06:35 AM
|
 |
Wrox Author
Points: 12,738, Level: 48 |
|
|
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 3,924
Thanks: 0
Thanked 82 Times in 80 Posts
|
|
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
|

July 11th, 2008, 06:38 AM
|
|
Authorized User
|
|
Join Date: Jul 2008
Location: , , .
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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,
|

July 11th, 2008, 06:53 AM
|
 |
Wrox Author
Points: 12,738, Level: 48 |
|
|
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 3,924
Thanks: 0
Thanked 82 Times in 80 Posts
|
|
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
|

July 11th, 2008, 07:27 AM
|
|
Authorized User
|
|
Join Date: Jul 2008
Location: , , .
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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 ?
|

July 11th, 2008, 07:42 AM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2007
Location: Newcastle, , United Kingdom.
Posts: 1,359
Thanks: 0
Thanked 31 Times in 31 Posts
|
|
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 -/
|

July 11th, 2008, 07:51 AM
|
|
Authorized User
|
|
Join Date: Jul 2008
Location: , , .
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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.
|

July 11th, 2008, 07:57 AM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2007
Location: Newcastle, , United Kingdom.
Posts: 1,359
Thanks: 0
Thanked 31 Times in 31 Posts
|
|
'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 -/
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
 |